Jump to content

Pointer collision with objects?


AramCP
 Share

Recommended Posts

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 :P

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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