Jump to content

Arcade physics overlap not working as documented?


spandy
 Share

Recommended Posts

I'm working on some conditional collisions for which I need to handle the result of the collision myself, without Phaser performing separation and physics on the bodies. From the docs for Physics.Arcade.overlap:

 

Unlike collide the objects are NOT automatically separated or have any physics applied, they merely test for overlap results.

 

I could misunderstand what this means, but I thought that it would cause collisions to be checked for but not actually happen unless done so in game code. What I find is that I can use overlap() and collide() interchangeably and they seem to do the same thing. With overlap(), my sprite gets blocked just like it does with collide(). It even bounces.

 

Looking at World.js, this doesn't seem surprising as overlap() and collide() call the exact same collideHandler which always calls a separation routine.

 

Is this a Phaser or documentation bug or am I reading this wrong?

Link to comment
Share on other sites

The only obvious difference that I have noticed is that collide only seems to be called if the collision is due to velocity being applied to one of the two sprites, while overlap is called simply if the sprites are touching.

 

I noticed this when I had a sprite which was the child of another sprite. If I attempted to test for collision between the child sprite and some other object in the game, it seemed to never collide. If using overlap, it worked. From what I could tell, this was because I was applying the velocity to the parent sprite, not the child sprite.

Link to comment
Share on other sites

I didn't read the documentation properly. Allow it doesn't throw an error, the documentation doesn't support calling overlap() on a TilemapLayer. You can call collide(), but not overlap(). This actually makes sense when you think about it, because they layer itself is composite.

 

It's possible a bug does exist if you've seen this on other game objects, but I haven't tested it myself.

Link to comment
Share on other sites

To clarify, I was trying to use overlap() rather than collide() because collide was doing separation regardless of whether my processCallback function returned true or false. Therein lies the possible bug. It's nothing to do with overlap() and everything to do with collide().

 

Today I can't see a way of doing custom collision detection against a tilemap layer. The separation firing effectively means a collision occurred.

Link to comment
Share on other sites

If you do this:

collide(someSprite, someTilemapLayer, function() {console.log("Collision")}, function() {return false});

Parameter 3, the custom collision handler, will not fire because parameter 4 always returns false. As documented. However the separation happens and someSprite does get blocked.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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