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

2015/5/20

Having trouble with my platform game

mcyr116 mcyr116

2015/5/20

#
When I go to the new level, I would like the score to come, as is, to the new level. All I can get it to do is reset. The code is at: http://www.greenfoot.org/scenarios/13948
danpost danpost

2015/5/20

#
Because the hero is passed to your WaterWorld world, you have enough information in the constructor to set the score counter of that new world to that of the old one. However, you must execute the following line first (before adding the hero into the new world):
Levels lastWorld = (Levels)hero.getWorld();
as once you add the hero to the new world, any reference to the old one is lost. Then, after you add the new Score object into the new world (via the call to the 'resetScore' method), you can execute the following line to set the current score:
addScore(lastWorld.getScore());
mcyr116 mcyr116

2015/5/20

#
Thank you soooo much! I was close on my own, but just couldn't get there!
You need to login to post a reply.