Jump to content

Check if coordinate is within sprite


krabban
 Share

Recommended Posts

Hi!

I want to check if a coordinate is occupied before I spawn a new sprite.
Are there any easy ways of checking if a sprite occupies a given coordinate?

Something like:

if( !isOccupied( x, y ) ) {

    //Do something

}

 

Any help or pointers would be greatly appreciated.

 

Link to comment
Share on other sites

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

 Share

  • Recently Browsing   0 members

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