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

2013/2/7

Set a new world from a class in Actor

Solringolt Solringolt

2013/2/7

#
I'm trying to make a menu, when you click on "Jouer" the game should start with wolrd: Level1 I tried it like this:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class jouer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class jouer extends menu
{
    /**
     * Act - do whatever the jouer wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private GreenfootImage jouer1;
    private GreenfootImage jouer2;
   
    
    public jouer()
    {
        jouer1 = new GreenfootImage("menu_jouer.png");
        jouer2 = new GreenfootImage("menu_jouer2.png");
    }
    public void act() 
    {
        if ( Greenfoot.mouseClicked(this))
        {
            setImage(jouer2);
            Greenfoot.delay(50);
            Level1 level1 = (Level1) getWorld();
            Greenfoot.setWorld(level1);
        }
        else
        {  
            setImage(jouer1);
        }
    }    
}
But i got an error when running the game.. How can i solve that problem. P.S.: My game is in french ^^
Gevater_Tod4711 Gevater_Tod4711

2013/2/7

#
Propably your exception is a IllegalCastException. When your jouer object is clickt the world should be set to level1 but it is no level one when you try to cast it in line 30. Instead of your current lines 30 and 31 you should try: Greenfoot.setWorld(new Level1());
Solringolt Solringolt

2013/2/7

#
Thx a lot it works with this!
You need to login to post a reply.