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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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