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


1 2 3 4 5 6 7 | // instead of Greenfoot.setWorld( new MyWorld()); // use MyWorld myWorld = new MyWorld(); Greenfoot.setWorld(myWorld); // then follow with this myWorld.counter.setValue(counter.getValue()); |
1 | myWorld.cannonCoins = cannonCoins; |
1 | myWorld.cannonCoins.setValue(cannonCoins.getValue()); |
1 2 3 | Space space = new Space(); Greenfoot.setWorld(space); space.returnCannonCoins().setValue(returnCannonCoins().getValue()); |
1 2 3 4 | Space space = new Space(); Greenfoot.setWorld(space); Space oldSpace = (Space) getWorld(); space.returnCannonCoins().setValue(oldSpace.returnCannonCoins().getValue()); |