Jump to content

Collision Detection


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

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.

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.


  • Recently Browsing   0 members

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