I have a space invaders game and in this game iI have a counter that hold "coins" and I have a retry button after you die that will set the world back and I want to know how to keep the amount of coins in the counter even if I press the retry button
// instead of Greenfoot.setWorld(new MyWorld()); // use MyWorld myWorld = new MyWorld(); Greenfoot.setWorld(myWorld); // then follow with this myWorld.counter.setValue(counter.getValue());
myWorld.cannonCoins = cannonCoins;
myWorld.cannonCoins.setValue(cannonCoins.getValue());
Space space = new Space(); Greenfoot.setWorld(space); space.returnCannonCoins().setValue(returnCannonCoins().getValue());
Space space = new Space(); Greenfoot.setWorld(space); Space oldSpace = (Space) getWorld(); space.returnCannonCoins().setValue(oldSpace.returnCannonCoins().getValue());