khleug35 Posted March 19, 2018 Share Posted March 19, 2018 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 More sharing options...
Recommended Posts