AramCP Posted January 2, 2017 Report Share Posted January 2, 2017 Hi guys, im implementing touch controls to my game because i want to export it to android in the future, its the first time i do that and i want to know how can i make something that detects if the pointer is colliding with a sprite. I am using this for movements of the player and it works: if(game.input.activePointer.leftButton.isDown && game.input.activePointer.position.x <= 128){ player.body.velocity.x = -velocityy; player.animations.play('left'); return; } And the same for the right. So i want to make something like that, but instead of x position, i want to dettect if the pointer is touching a sprite, any ideas about how can i do that? thanks Quote Link to comment Share on other sites More sharing options...
PhasedEvolution Posted January 2, 2017 Report Share Posted January 2, 2017 What do you mean by touching? inside the sprite body ? Quote Link to comment Share on other sites More sharing options...
AramCP Posted January 2, 2017 Author Report Share Posted January 2, 2017 Just now, PhasedEvolution said: What do you mean by touching? inside the sprite body ? By touching i mean that the pointer is over the sprite body yes, like in this image: http://prnt.sc/dqoza Lets imagine that the red ball is the mouse poiner, so as you can see, he is above the sprite called play. Quote Link to comment Share on other sites More sharing options...
PhasedEvolution Posted January 2, 2017 Report Share Posted January 2, 2017 var input = game.input.activePointer.position; if( (input.x > sprite.body.x && input.x < sprite.body.x+sprite.width) && (input.y > sprite.body.y && input.y < sprite.body.y+sprite.height) ) {...} Quote Link to comment Share on other sites More sharing options...
AramCP Posted January 2, 2017 Author Report Share Posted January 2, 2017 Just now, PhasedEvolution said: var input = game.input.activePointer.position; if( (input.x > sprite.body.x && input.x < sprite.body.x+sprite.width) && (input.y > sprite.body.y && input.y < sprite.body.y+sprite.height) ) {...} Nice, didnt thought in that, thanks man! Quote Link to comment Share on other sites More sharing options...
samme Posted January 3, 2017 Report Share Posted January 3, 2017 Think you can do Phaser.Rectangle.containsPoint(sprite.body, activePointer.position); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.