How can I control a sprite with on screen buttons

#1

How can I control my sprite with the on screen interactive buttons I’ve created? Nothing seems to be working, and tried a few methods. I can get my player to change tint onDown and then change back when out, but I cannot get player.setVelocityX(200); to work at all.

#2

Can you share a bit of code so that we can help you identify the problem?

#3

So the first is my left button, on screen control. It only moves the player one frame each time the pointer is over, as opposed to continuous. It is in the create function, and I know it should really be in update, however I cannot find documentation on how to extend the touch functions to be onlock, or onhold so that the player may run.

this.leftButton = this.add.image(100, 500, ‘left_button’).setOrigin(0).setName(‘left_button’).setInteractive();
this.leftButton.on(‘pointerover’, ()=>{
player.setVelocityX(-300);
player.anims.play(‘walk’, true);
player.flipX = true;
});

The second is my cursors update. This code works fine and moves the player as it should. I am looking to find the equivalent to a touch event so I can have this work on mobile.

if (cursors.left.isDown){
player.setVelocityX(-300);
player.flipX = true;
player.anims.play(‘walk’, true);
}