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

2012/1/12

"Saving" the World

DMCGames DMCGames

2012/1/12

#
Is there a way I could store the current objects in this world then go to like the next world and come back everything the same?
Duta Duta

2012/1/13

#
Yes - there are probably better methods, but I use the following (I haven't got any uploaded scenarios with multiple levels, but I've made a few) method: Once you're moving on to the next level (with the setWorld(new NextWorldName()) method), pass the objects to the next world in its constructor. In other words, you'd have it like this: setWorld(new NextWorldName(getObjects(null))) and then in the NextWorldName class, you'd obviously have to modify its code so that its constructor takes a java.util.List as a parameter, and then store it. Then, when you want to go back to the first world, you do the same (except this time its something like
//Fields section
java.util.List objectsList = //The list it was passed as a parameter.

//Wherever you are in the code
setWorld(new FirstWorldName(objectsList)
, and you have to include something that makes sense of that list and re-adds the objects. If you want the objects in their same positions you might want to pass something like a 2d int array of x and y positions between the worlds which you can use) If I'm not making sense, tell me and I'll try to be clearer. If anyone else has a better method (which I'm sure they must do :) ) please post it and we'll all learn something :D
You need to login to post a reply.