Jump to content

about Joystick Plugin: Dpad movement


khleug35
 Share

Recommended Posts

Is Joystick Plugin: Dpad possible to achieve the player move to  8 direction??

    update: function () {

        var maxSpeed = 300;

        if (this.stick.isDown)
        {
            this.sprite.body.velocity.set(0);

            if (this.stick.direction === Phaser.LEFT)
            {
                this.sprite.body.velocity.x = -maxSpeed;
            }
            else if (this.stick.direction === Phaser.RIGHT)
            {
                this.sprite.body.velocity.x = maxSpeed;
            }
            else if (this.stick.direction === Phaser.UP)
            {
                this.sprite.body.velocity.y = -maxSpeed;
            }
            else if (this.stick.direction === Phaser.DOWN)
            {
                this.sprite.body.velocity.y = maxSpeed;
            }


           //8 direction movement

                  else if (this.stick.direction === Phaser.UP && this.stick.direction === Phaser.LEFT)
            {
                this.sprite.body.velocity.x = -maxSpeed;
                this.sprite.body.velocity.y = -maxSpeed;
            }
             else if (this.stick.direction === Phaser.UP && this.stick.direction === Phaser.RIGHT)
            {
                this.sprite.body.velocity.x = maxSpeed;
                this.sprite.body.velocity.y = -maxSpeed;
            }
              else if (this.stick.direction === Phaser.Down && this.stick.direction === Phaser.LEFT)
            {
                this.sprite.body.velocity.x = -maxSpeed;
                this.sprite.body.velocity.y = maxSpeed;
            }
            else if (this.stick.direction === Phaser.Down && this.stick.direction === Phaser.RIGHT)
            {
                this.sprite.body.velocity.x = maxSpeed;
                this.sprite.body.velocity.y = maxSpeed;
            }        }
        else
        {
            this.sprite.body.velocity.set(0);
        }

    }

Thanks

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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