Where are you calling this method from (show the method that calls this one)? Also, what class is this 'newDragon' method in?
// add an instance boolean to the class
private boolean onDragon = false;
// code for counter
if (!onDragon && !getIntersectingObjects(Dragon.class).isEmpty())
{
// increment counter
// any other actions
onDragon = true;
}
if (onDragon && getIntersectingObjects(Dragon.class).isEmpty()) onDragon = false;// Dragon class field
static Dragon liveDragon = null;
// in Dragon constructor
liveDragon = this;
// when killed
liveDragon = null;
// for the act method
if (this == liveDragon)
{
// code for live dragon
// when dragon dies
liveDragon = null;
}
else
{
// code for dead dragon
}
if (liveDragon == null) getWorld().addObject(new Dragon(counter), 0, 400);