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

2013/5/3

Score Help

SWAG SWAG

2013/5/3

#
When I switch levels by score goes to 0 again. How can I continue my score from previous level. I'm using the counter sub class. Can someone help me right a code that would allow to continue score.
danpost danpost

2013/5/3

#
When creating the new world, before setting it, set the counter of the new world to that of the old. As an example, this code transfers the value of the counter in the old world to the counter in the new one.
MyWorld newWorld = new MyWorld();
Counter newCounter = (Counter) newWorld.getObjects(Counter.class).get(0);
Counter oldCounter = (Counter) getWorld().getObjects(Counter.class).get(0);
newCounter.setValue(oldCounter.getValue());
Greenfoot.setWorld(newWorld);
SWAG SWAG

2013/5/3

#
danpost wrote...
When creating the new world, before setting it, set the counter of the new world to that of the old. As an example, this code transfers the value of the counter in the old world to the counter in the new one.
MyWorld newWorld = new MyWorld();
Counter newCounter = (Counter) newWorld.getObjects(Counter.class).get(0);
Counter oldCounter = (Counter) getWorld().getObjects(Counter.class).get(0);
newCounter.setValue(oldCounter.getValue());
Greenfoot.setWorld(newWorld);
List<Counter> counters = getWorld().getObjects(Counter.class); Counter counter = counters.get(0); counter.add(50); This is my code in my shooting class. I get my points from shoot class. It add the point when bullet it enemy. what code and where would I put it so it doesn't reset when changing levels.
You need to login to post a reply.