Jump to content

Phaser.arcade collide and overlap difference and "separation"..?


BdR
 Share

Recommended Posts

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?  :huh:
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

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

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

 Share

  • Recently Browsing   0 members

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