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

2017/3/31

How to make the game wait before changing worlds?

HardToFindAName HardToFindAName

2017/3/31

#
So I have the following situations: The world, a map which I'll call Harta: A banner appears on Harta saying Election Day. Banner waits a couple of seconds then disappears. Things happen on the map and it waits a couple of seconds; World changes. That's what I want it to do, at least. In my case, it happens like this: A banner appears on Harta saying Election Day. Banner waits a couple of seconds then disappears. Things happen on the map but world changes simultaneously and you can't see the changes. Basically, it doesn't wait. Here's the code which should change the map:
if (elecDem>=270)
                {

                    Greenfoot.delay(240);
                   


                    Greenfoot.setWorld(new Hillary());
                
                }

                else
                {

                    if (elecRep>=270)
                    {
                        Greenfoot.delay(240);

                        Greenfoot.setWorld(new Donald());
                    }
                
            }
I tried many things, like stopping Greenfoot then starting it again and adding delays, but nothing's working. I'd be glad if someone could help me! :)
danpost danpost

2017/3/31

#
I really think that using delays was not the best way to go here. Instead of using all these delays, maybe you should have just used an instance timer field and have action done at specific timer values. At any rate, with the code given above, I cannot tell where those map changes are being done. All I see are some conditional checks, some delays and world changes.
HardToFindAName HardToFindAName

2017/3/31

#
Thank you for your help. Yet, I think I'll stick with something different: I'll give up with changing the worlds and I'd rather set a new image to this world. Perhaps the delays won't work because it delays a single world, I don't know. That should do it, shouldn't it?
danpost danpost

2017/3/31

#
HardToFindAName wrote...
Thank you for your help. Yet, I think I'll stick with something different: I'll give up with changing the worlds and I'd rather set a new image to this world. Perhaps the delays won't work because it delays a single world, I don't know. That should do it, shouldn't it?
Maybe these delays belong in the Donald and Hillary worlds? However, you may be right; what you said should do it.
HardToFindAName HardToFindAName

2017/3/31

#
Hi, I'm facing a problem at the moment. Look at this code:
if (getWorld()!=null)
     {
         x=true;
         Greenfoot.delay(240);
         getImage().setTransparency(0);
         y=Results.getelecDem();
         if (y>=270)
         {
             getWorld().addObject(castigator,450,300);
             Greenfoot.delay(240);
             castigator.setImage(new GreenfootImage("hillary.png"));
             
            }
            else
            {
             Greenfoot.stop();
             while(i>0)
             {
                 i--;
                }
             Greenfoot.start();
             Greenfoot.setWorld(new Donald());
            }
            

     }
Basically: I check if the banner was added; I delay the game; I set the transparency to 0 so it disappears without removing it from the world; I get the elecDem number and store it in a local variable which I compare then with the number I need - 270 I add an invisibile image in the game I want to freeze the game at this point for a little I change the image to the one I want Done Well I still have a problem with freezing the game. It simply shows the picture and I can't figure it out. Could you please help me?
HardToFindAName HardToFindAName

2017/3/31

#
Don't mind the else part, it's always going to enter the first condition because I set elecDem to 280 until I can solve the problem.
You need to login to post a reply.