Jump to content

Phaser + Isometric plugin, how to detect overlap or intersection


Darko
 Share

Recommended Posts

Hi, I'm starting with Phaser + Isometric plugin and is pretty cool.

I think it has what I need for now, but now I'm stuck with some tests...

I'm trying to detect when a srpite is hidden by another sprite in the isometric map.

Something similar to? https://phaser.io/examples/v2/sprites/overlap-without-physics

I tried with intersects without results, I think this is because colliding avoid intersections.

I tried also with overlap, but I have results only when collides, and I want to know it without colliding.

Scene A:

scene_a.png

Blue cube is not colliding but has a hidden part because of isometric ordering.

That is what I need to detect.

Scene B:

scene_b.png

Blue cube is not hidden on any part, so I don't mind...

Any ideas?

Thank you all in advance!

Link to comment
Share on other sites

The plug-in has nothing like this out of the box, so you'd have to write some routine to do this. I'm pretty sure if you use the .isoBounds or .body Cube properties (bottom, top, backX, backY, frontX and frontY) to compare the positions/sizes of items you should be able to make something workable. I think the naive approach of checking if the sprite overlaps the other doesn't adequately solve the problem, because there are situations where the rectangular sprites' transparent areas are overlapping, which is a false positive. If this is good enough for you however, you should be able to just use the same method as in 'overlap without physics', as IsoSprites extend normal Phaser Sprites.

function checkOverlap(isoSpriteA, isoSpriteB) {

    var boundsA = isoSpriteA.getBounds();
    var boundsB = isoSpriteB.getBounds();

    return Phaser.Rectangle.intersects(boundsA, boundsB);

}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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