ptotheaul Posted February 4, 2018 Share Posted February 4, 2018 I have a game where a sprite(ball) is dropped and then I need to determine what the sprite(object) is directly under it is, where there are a lot of object sprites. If an object sprite covers another object sprite I would only want the top object sprite to be detected(ideally if the ball sprite overlapped the visible area of multiple object sprites I would like all of the of the ball/objects detections to show). I've looked into .intersects and even just using a single point with .contains but can't figure it out. If I check for collisions is there a way to just check for the visible(not covered up by other sprite) area? Link to comment Share on other sites More sharing options...
casey Posted February 4, 2018 Share Posted February 4, 2018 Why not just detect the sprite overlap? You can trigger any sprite that the ball overlapped with on its way, and then when the ball has stopped moving, check what it is overlapping with. Without physics overlap: http://phaser.io/examples/v2/sprites/overlap-tween-without-physics With physics example overlap: Link to comment Share on other sites More sharing options...
ptotheaul Posted February 4, 2018 Author Share Posted February 4, 2018 The ball is not moving. it just gets placed in a certain spot. I've tried using overlapping but it returns every object that the ball overlaps with and I just want it to return the object that is on the top(or ideally the objects that are not covered by another oject). Link to comment Share on other sites More sharing options...
casey Posted February 5, 2018 Share Posted February 5, 2018 Sounds like you'll need to do layers, z-index style, but I'm not sure I understand your problem. Link to comment Share on other sites More sharing options...
samme Posted February 5, 2018 Share Posted February 5, 2018 You should be able to check sprite.z. Largest z is on top. Link to comment Share on other sites More sharing options...
Recommended Posts