Jump to content

On Screen Buttons for Movement in Phaser 3


di-de
 Share

Recommended Posts

I want to deploy my game to Android through Apache Cordova, so I need buttons on screen for movement. I have tried it doing and almost succeeded. I am using Phaser 3.24.0 and Arcade Physics.

My independent move function:

function move(dir) 
{
    if (dir == "left") 
    {
        this.player.setVelocityX(-100);
        this.player.anims.play('move', true);
        this.player.flipX = true;

    } 
    else if (dir == "right") 
    {
        this.player.setVelocityX(100);
        this.player.anims.play('move', true);

    } 
    else 
    {
        this.player.setVelocityX(0);
        this.player.anims.play('idle', true);
    }
}

And the update function :

function update() 
{
    if (cursors.left.isDown) 
    {
        move("left");

    } 
    else if (cursors.right.isDown) 
    {
        move("right");

    } 
    else 
    {
        move();
    }
    this.leftArrow.on("pointerdown", function() 
    {
        move("left");

    });
    this.rightArrow.on("pointerdown", function() 
    {
        move("right");

    });
}

The keyboard function works very well, and when I press the button (sprites) it moves for just a few pixels and stops. What can be done to achieve the desired effect?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...