Jump to content

Check if coordinate is within sprite


krabban
 Share

Recommended Posts

Sorry, I didn't phrase my question as well as I should have.
 

if(x and y equals sprite.x and sprite.y) {
    // Do something
}

If I'm understanding this right, this snippet only returns true if my x and y equals the sprites x and y.
This might return false even if my x and y are within the sprites collision body.

I need something like:

if( !(x and y are within sprite.collisionBody) ){
    // Do something
}

But I'm unsure what to compare against.

Link to comment
Share on other sites

On 1/27/2016 at 7:28 AM, krabban said:

I want to check if a coordinate is occupied before I spawn a new sprite.

If you want to do this you need to check every sprite in your game and see if it overlaps that point. If you've enabled physics for your sprite then it has a property called "body" that has properties x, y, width, and height. Those form a rectangle that you can use to check for intersection with your point.

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...