You can retrieve the coordinates of the actor by calling getX()
and getY()
, as you do it for other actors.
If you like to call methods for the "current" actor, you might like to use this
, in example this.getX()
. But it is only necessary, if you need to resolve some ambiguity. Commonly you can just call the method.
public void move()
{
Dog bill = getOneIntersectingObject(Dog.class);
Marker bone = getOneIntersectingObject(Marker.class);
if (bone == null)
{
Marker marker = new Marker();
getWorld().addObject(marker, getX(), getY());
}
super.move(1);
}
Changes necessary as obvious from the shown excerpt:
- The parameter of the second
getOneIntersectingObject()
is Marker.class
, because you seem to want this.
- No semicolon after the parenthesis of the
if
. If you don't remove it: This semicolon is an empty statement, so the if
will have no effect. The block between the braces following it will always be executed.
- Rename the second
bone
as marker
to show your intention. (It would "shadow" the "outer" bone
, additionally, but this is no problem here.)
- Call
addObject()
with the right parameters: the object to place (the new marker), and its coordinates (retrieved by calling getX()
and getY()
).