Jump to content

Check to see if anything exists where sprite will be added


drspock11
 Share

Recommended Posts

How can I check if a sprite will collide with anything already on the screen prior to adding it? I add the sprite in the update loop, and game.physics.arcade.overlap or game.physics.arcade.collide does not detect the collision until after the sprite has been added and the update loop has exited at least once.

I've been searching extensively but cannot find the answer to this seemingly simple question.

Thanks for any help.

Link to comment
Share on other sites

you can use any object with a public x and y property with game.world.getClosestTo to find the closest gameobject to a point. You can then test if that gameobject would overlap your new sprite by comparing against it's xy co-ordinates and its width and height against the new sprite

var closest = game.world.getClosestTo({x:500, y:500});

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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