Sign in to follow this  
biklas7

Move to pointer (Touch/Mouse)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.