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

2016/11/20

setWorld

Nosson1459 Nosson1459

2016/11/20

#
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class MainWorld here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class MainWorld extends World
{
    public int world;
    /**
     * Constructor for objects of class MainWorld.
     * 
     */
    public MainWorld()
    {    
        super(750, 650, 1,false); 
        
    }
    public void act()
    {
        world=1;
        if(world==1)
        {
            Greenfoot.setWorld(new Menu());
        }
        if(world==2)
        {
            Greenfoot.setWorld(new Scene());
        } 
    }
}
both Scene and Menu extend MainWorld wats wrong with this it doesn't change worlds stays on scene no matter wat the world variable =
Super_Hippo Super_Hippo

2016/11/20

#
Does your scenario start with the MainWorld class? Right-click on it and select 'new MainWorld()'.
Nosson1459 Nosson1459

2016/11/21

#
thnx it worked is there any way 2 set that in coding
danpost danpost

2016/11/21

#
Nosson1459 wrote...
is there any way 2 set that in coding
That (what you did by right-clicking on the world class and selecting 'new MainWorld()') is the basic way to set the initial world. Any code would be executed after the initial world was set and therefore is useless in selecting the initial world.
Nosson1459 Nosson1459

2016/11/21

#
oh
Nosson1459 Nosson1459

2016/11/22

#
if(Greenfoot.mousePressed(this))
        {
            Greenfoot.setWorld(new Scene());
        }
this doesnt work (its in an actor) i forgot 2 call the method
You need to login to post a reply.