1
public void move()
{    
    //if (this.getWorld().getObjects(Marker.class).isEmpty())
    Dog bill = getOneIntersectingObject(Dog.class);
    Marker bone = getOneIntersectingObject(Dog.class);
    if (bone == null); 
    {
        Marker bone= new Marker();
        getWorld().addObject(marker.getX(), marker.getY());
    }
    super.move(1);
}

I'm trying to reference the location of my current actor subclass (dog) in order to place a marker(bone) of another subclass at the coordinates it is located at.

  • Welcome to StackOverflow! Please take the [tour] and read "[ask]". Just in case: If you have any additions to your question, please [edit] it instead of posting a comment. – the busybee Mar 08 '20 at 21:21

1 Answers1

0

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()).
the busybee
  • 10,755
  • 3
  • 13
  • 30