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

2016/12/31

How can I check if there is a certain object in a certain location ?

alexilasi alexilasi

2016/12/31

#
How can I check if there is a certain object in a certain location ? I've tried with getObjectsAt, but that method returns a string of objects. P.S. I know the X and Y coordinates.
danpost danpost

2016/12/31

#
alexilasi wrote...
How can I check if there is a certain object in a certain (known) location ? I've tried with getObjectsAt, but that method returns a string of objects.
The 'getObjectsAt' method returns a List of objects (not a string of objects). The List class 'contains' method might be useful here:
1
if (getObjectsAt(x, y, class).contains(actor))
You will have to supply the values for 'x', 'y', 'class', and 'actor'. Be aware, however, that any part of that actor's image can be in that certain location to be listed. This means that in a world with cell size being one, the actor can physically be at (2*wide-1)*(2*high-1) possible locations to be considered at that one location ('wide' and 'high' being the dimensions of the image set to the actor. It you require that the x and y of the actor be at that certain location then use:
1
if (actor.getX() == x && actor.getY() == y)
You need to login to post a reply.