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

2014/11/18

Counter Problems

Konzuk Konzuk

2014/11/18

#
I'm making a game where the spaceship can pick up astronaughts and is destroyed by asteroids. I have an end screen when you're killed, but I can't figure out how to add a counter that displays on the end scene.
public void remove()
        {
        Actor Ship;
        Ship = getOneObjectAtOffset(0, 0, Ship.class);
        if (Ship != null)
        {
            World world;
            world = getWorld();
            world.removeObject(Ship);
            world.addObject(new End(), world.getWidth()/2, world.getHeight()/2);
            world.addObject(new Counter(), world.getWidth()/2, world.getHeight()/2);
            Greenfoot.stop();
        }}
danpost danpost

2014/11/18

#
On line 11, you are creating a NEW Counter object, whose fields are created and set to their initial default values when the object is created. Remove that line. You want the original Counter object to either show or have its value displayed somehow on the image of the End object. One simple way may be just to change the paint order (inserted somewhere within the 'if' block):
world.setPaintOrder(Counter.class, End.class);
You need to login to post a reply.