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

2014/10/21

Is it possible to reconstruct World sub classes?

forteddyt forteddyt

2014/10/21

#
More specifically: I want to have two 'Phases' in my game, "Phase 1" would be the main menu, which I'd like to have a constructor with parameters of (704, 704, 1), and when a player hits the start button, the World subclass would react with entering "Phase 2", which would reconstruct the, at the moment world with (704, 704, 1) parameters, into a world with (22, 22, 32) parameters. Basically, I'm just asking if it's possible to do that or if it's not a thing.
danpost danpost

2014/10/21

#
No matter how you go about it, the two worlds will be distinctly different worlds. Once a world is created, its dimensions are set in stone. The only way to go around this is to create the code necessary to convert a pixel cell-sized world into a grid world. If you are wanting two distinct worlds you can create a second subclass of World for your second world and use the Greenfoot class method 'setWorld' to make the second world active. For example, from MenuWorld:
1
Greenfoot.setWorld(new GridWorld());
This would create a new grid world and set it as the active world from your menu world.
forteddyt forteddyt

2014/10/21

#
Oh wow, I can't believe I didn't see that method :/. Thanks though, that's exactly what I was looking for. I was messing around with sub-sub classes of World and tried reconstructing it like that, but was calling just "new subSubClass();" instead of "Greenfoot.setWorld(new subSubClass());". Thanks for the quick and simple response! :D
You need to login to post a reply.