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

2014/5/11

Object being erased and re-added

WhiteWolf13 WhiteWolf13

2014/5/11

#
ok, so currently I am trying to program a game in which the main hero (a round dot) can go off the edge of the screen, and appear in a whole new world (magical I know). I've managed to code that part by preparing a new world depending on where he goes, however, when he goes off the edge of the screen he is basically removed and re-added once the new world has been generated. meaning, all his variables such as "health" and "stamina" are reset to what they are when he first spawns, and it is as if a fake new clone of the hero is now being played, instead of the "original" one. does anyone know a way around this? as I've been thinking for a while but to no avail. any help would be great, thank you.
danpost danpost

2014/5/11

#
Just pass the main hero to the new world when you create it and have the new world add it (the original) into its realm (just like an argument to a method).
WhiteWolf13 WhiteWolf13

2014/5/12

#
so will I have to pass each individual variable from the original hero into the new world or is there any way of just passing all of him?
davmac davmac

2014/5/12

#
If you remove the object from one world and add it into the second, as danpost describes, it will retain all its variable values.
You need to login to post a reply.