In my game I'm trying to make it where the counter will move to the center of the screen once the game is over so it is next to the "Score:" text on screen. Every time I try to use .setLocation on the Counter the program stops running. It is also doing the same thing if I try to remove the Counter from the world. These are the two codes that I am working with. I am going to add a link to my scenario soon. EDIT:here is the link
public void act()
{
int xpos = getX() - 5;
if (xpos <= 0)
{
getWorld().removeObject(this);
}
else
{
setLocation(xpos, getY());
Actor player = getOneObjectAtOffset(0,0,RocketPlayer.class);
if (player != null)
{
getWorld().removeObjects(getWorld().getObjects(RocketPlayer.class));
getWorld().removeObjects(getWorld().getObjects(Fuel.class));
getWorld().setBackground(new GreenfootImage("gameOver.jpg"));
getWorld().removeObjects(getWorld().getObjects(Astroid.class));
getWorld().removeObjects(getWorld().getObjects(Counter.class));
Greenfoot.delay(250);
Greenfoot.setWorld(new MainMenu());
}
}
} public AstroidWorld()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
player = new RocketPlayer();
gameTime = new Timer();
counter = new Counter();
addObject(player,30,200);
addObject(gameTime,550,20);
addObject(counter,20,350);
}
public void act()
{
if (Greenfoot.getRandomNumber(200)<5)
{
addObject (new Astroid(), 560, Greenfoot.getRandomNumber(400));
}
if (player.getWorld() != null)
{
gameTimer = (gameTimer+1)%60;
if (gameTimer == 0)
gameTime.increaseTime();
}
if (Greenfoot.getRandomNumber(200)<5)
{
addObject (new Fuel(), 560, Greenfoot.getRandomNumber(400));
}
if ( player.getWorld() == null)
{
counter.setLocation(100,200);
}
}
public Counter getCounter()
{
return counter;
}
public void moveCounter()
{
counter.setLocation(200,100);
}
}
