Jump to content

Move to pointer (Touch/Mouse)


biklas7
 Share

Recommended Posts

Hello, I'm new to Phaser and i'm really getting into it. I've already made a couple of tutorials, and now i want to make my own game.

 

In the game I'm trying to develop, when I press the screen with a touch or with the mouse, the player should move to the point I touched with a certain amount of acceleration.

 

In the official Phaser examples i've got this piece of code:

 

player.rotation = game.physics.arcade.moveToPointer(player, 600, game.input.activePointer, 600);

 

With this code the player follows the mouse pointer and never stops unless the mouse is stopped, and i want to simply click or touch the screen and put the player moving to the point i've touched or clicked and stop there until i click or touch again in the screen.

 

Can someone help me?

 

Regards,

António

Link to comment
Share on other sites

I've kind of found a solution.. This code seems to work:

 
if (game.input.mousePointer.isDown) {
        player.rotation = game.physics.arcade.moveToXY(player, game.input.x, game.input.y, 600, 600);
}
 
Anyway, if someone have a better solution it will be welcomed.
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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