JackBid Posted November 11, 2013 Share Posted November 11, 2013 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 More sharing options...
Mike Posted November 12, 2013 Share Posted November 12, 2013 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 23. 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 12. when body 1 collide play animation and set iscollideAnimation to true3. 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 More sharing options...
JackBid Posted November 12, 2013 Author Share Posted November 12, 2013 3. Check if body exit a collision state (in the update) and then check current frame stop on it, and also set isCollideAnimation = falseMy 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 More sharing options...
jcs Posted November 12, 2013 Share Posted November 12, 2013 if it was 'in the collision state' in the last frame, and it's not in this frame, I'd say it just 'exited' the collision state... Link to comment Share on other sites More sharing options...
Recommended Posts