BdR Posted September 28, 2014 Share Posted September 28, 2014 I'm working on a endless runner where the player avoids bombs and picks up coins, and it's coming along nicely. Both coins and bombs are in the same group of objects, and I use overlap() to check for collisions between player and objects. This all works fine, although I find it weird that overlap also handles sprites that are not alive (alive=false). So now I'm trying to understand the overlap and collide functions better and this is what it says in the docs:collide(object1, object2, collideCallback, processCallback, callbackContext) → {boolean}The objects are also automatically separated. overlap(object1, object2, overlapCallback, processCallback, callbackContext) → {boolean}Unlike collide the objects are NOT automatically separated or have any physics applied, they merely test for overlap results. I've got 2 questions: 1) Maybe a stupid question but.. what does "separated" mean here? 2) As a general rule, what situations are best to use collide() and when best to use overlap() ? Link to comment Share on other sites More sharing options...
lewster32 Posted September 28, 2014 Share Posted September 28, 2014 The basic difference is that collide tries to stop any touching objects from overlapping. Not much more in it really - both will detect 'collisions' between two objects and will otherwise act pretty much identically. Typically, you'd use overlap for situations where you want to detect the meeting of two objects and do something, such as a player picking up a coin. Collide on the other hand would be used for situations such as bouncing off the head of an enemy, standing on a platform or a ball hitting a paddle - you want there to be a physical effect from the meeting of the two objects as well as (optionally) detecting the event. Link to comment Share on other sites More sharing options...
BdR Posted September 28, 2014 Author Share Posted September 28, 2014 Ah okay thanks for the answer. And about the "separated", does it mean the colliding objects are separated from each other? In other words after detecting the collision the 2 objects are moved in such a way that they are not overlapping anymore. Correct? Link to comment Share on other sites More sharing options...
Dumtard Posted September 29, 2014 Share Posted September 29, 2014 That is exactly what it means. Link to comment Share on other sites More sharing options...
lewster32 Posted September 29, 2014 Share Posted September 29, 2014 Yes, the objects' velocities will be modified so that they're kept apart - usually by stopping the first object and transferring its velocity to the second, though the bodies' mass and bounce properties will change how this is calculated. Link to comment Share on other sites More sharing options...
Recommended Posts