Jump to content

Collision Exit Detection


JackBid
 Share

Recommended Posts

I need to find a way to detect when a sprite exits collisions. My goal here is that when a sprite enters a collision an animation is played and when the sprite exits the collision the animation is paused leaving the sprite at a different frame from a sprite sheet. If there a simple built in function to phaser to achieve this? Or do I need to find a different solution.

 

Here is my simple code so far:

function update() {    game.physics.collide(cup, sprite2, collisionHandler, null, this);}function collisionHandler (obj1, obj2) {    cup.animations.play('fill', 10);}
Link to comment
Share on other sites

Let me describe what i get:

 

1. You have to sprites 

2. They collide (but you don't separate them and then) continue to collide until body 1 exist body 2

3. During the collision you want body 1 to play animation and when body 1 exist to stop the animation on the current frame

 

If so I can suggest this routine:

1. Add some property to body 1

2. when body 1 collide play animation and set iscollideAnimation to true

3. Check if body exit a collision state (in the update) and then check current frame stop on it, and also set isCollideAnimation = false

 

...

it may be wrong approach but you get the idea...also check this topic:

 

http://www.html5gamedevs.com/topic/1974-using-collision-detection-without-physics/?hl=collision

Link to comment
Share on other sites

 

3. Check if body exit a collision state (in the update) and then check current frame stop on it, and also set isCollideAnimation = false

My problem is that I do not know how to check if a body exits a collision state. I know how to check if it enters a collision, but not if it exits.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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