Jump to content

Control the player by directional swipe action


Recommended Posts

Hi everyone,


I'm following a Phaser tutorial by @bryanbibat , the Shoot'em up game.


The function moveTopoiter is good when play the game by mouse cursor. However, it hides my view on mobile touch screen. So that I want to improve the controlling of player on mobile touch by swipe action.


I tryng to replace these lines in the update function:

  if (this.input.activePointer.isDown &&        this.physics.arcade.distanceToPointer(this.player) > 15) {      this.physics.arcade.moveToPointer(this.player, this.player.speed);    }

with these

  if (this.input.activePointer.isDown ){      this.player.body.velocity.x = (this.input.activePointer.position.x - this.input.activePointer.positionDown.x) * 2;      this.player.body.velocity.y = (this.input.activePointer.position.y - this.input.activePointer.positionDown.y);    } else {      this.player.body.velocity.x = 0;      this.player.body.velocity.y = 0;    }

It works but the control isn't good. It isn'e sensitivre and jitter.


I've just read these post but it doesn't help.





Could anybody give me an advice?

Link to comment
Share on other sites

I'm not sure if swiping is a good control scheme for shmups since they require precision control.


One way of preventing the player's finger from covering the player's sprite is to let the pointer be at the back of the sprite e.g. 

    if (this.input.activePointer.isDown &&        this.physics.arcade.distanceToXY(this.player, this.input.activePointer.x, this.input.activePointer.y - 32) > 15) {      this.physics.arcade.moveToXY(this.player, this.input.activePointer.x, this.input.activePointer.y - 32, this.player.speed);    }

Another way is to have an on-screen virtual d-pad.

Link to comment
Share on other sites


  • Recently Browsing   0 members

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