Jump to content

Collision Detection


hoshomoh
 Share

Recommended Posts

I only want to do something for example increment my score the first time collision happened between objects. I don't want that action to happen in subsequent time when collision happens again between the same objects

 

I mean how do i check if two object have collided before, and stop them from colliding again.\

Or i may i remove collision property from an object after first collision happens 

Link to comment
Share on other sites

Try creating a Signal on the sprite you care about. In your custom collision handler you can fire the signal every time there is a collision.

 

Then, you can call addOnce (http://docs.phaser.io/Phaser.Signal.html#addOnce) to add a function that will be invoked the next time there's a collision between the two objects you care about. It will execute once, then never again (until you call addOnce again).

 

Would that help?

 

EDIT: I realize I'm being a little vague but I wanted to make sure I understand what you're trying to do before going into more detail. ( =

Link to comment
Share on other sites

so you could use the signal onBeginContact    and then fire up your custom function that will increment your score and maybe set a "timer" variable to the current game time + 2000 (ms)  and the next score incermental will only happen if game.time.now > timer..

 

or.. you use onbegincontact with "addOnce()  so the signal will be removed completely after the first collision...  

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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