Sign in to follow this  
JackBid

Collision Exit Detection

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);}

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.