This site requires JavaScript, please enable it in your browser!
Greenfoot back
Suavessence
Suavessence wrote ...

2020/10/12

Check if object exists at specific coordinate

Suavessence Suavessence

2020/10/12

#
Is there a way to use getWorld() to check if an object exists at a specific coordinate location?
Super_Hippo Super_Hippo

2020/10/12

#
‘getWorld()’ returns a world object. If you want to know if your actor is at (x|y), you could do this:
1
2
3
4
if (getX()==x && getY()==y)
{
    //do something
}
If you want to know if any object is at (x|y), you can do this:
1
2
3
4
5
6
7
8
9
10
if (!getObjectsAt(x, y, null).isEmpty())
{
    //do something
}
 
//or in case you want to execute the code in an Actor class
if (!getWorld().getObjectsAt(x, y, null).isEmpty())
{
    //do something
}
Suavessence Suavessence

2020/10/12

#
That helps, thank you!
You need to login to post a reply.