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

2016/6/17

Helicopter game need help with switching worlds!

joseph.a joseph.a

2016/6/17

#
hey I made a game similar but instead its a helicopter, I now want to switch between a night time and day time world. I want it to randomly switch when I hit reset to one of these worlds but I don't know how to do this is this possible can someone help me asap please!
Super_Hippo Super_Hippo

2016/6/17

#
If you are using two different worlds -- let's say Day and Night -- and Day is the initial world, you could use this line in the constructor of the Day world:
if (Greenfoot.getRandomNumber(2)==0) Greenfoot.setWorld(new Night());
If the only difference is the background, you can stick with one world and set the background randomly.
joseph.a joseph.a

2016/6/17

#
My worlds are set up like HelicopterWorld which is night and is the world the game always starts with the DayTime which is the day time world and them starterscreen which is a starter screen. When I hit reset a starter screen comes up then i hit enter it starts my game im just trying to change the background to day randomly.
valdes valdes

2016/6/17

#
If you are just changing the image of the background you don't need class DayTime at all. in your HelicopterWorld add the following:
if (Greenfoot.getRandomNumber(2)==0) {
  setBackground("day.jpg");
} else {
  setBackground("night.jpg");
}
You need to login to post a reply.