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

2013/1/11

Cannot be cast

Thellior Thellior

2013/1/11

#
If got a problem with my game. If got 2 worlds called MenuDijkDoorBraak and FloodWorld. My first world that i activate is MenuDijkDoorBraak. In this world if got a character select. I use this code to choose which character you play.
public class MenuDijkDoorBraak extends World
{
    private int Charselect;
    public int getCharselect()
    {
        return Charselect;
    }
    public int setCharselect(int x)
    {
        Charselect=x;
        return Charselect;
    }
}
For the character's i use
public class politieSelect extends DijkDoorBraakMenu
{

    public void act() 
    {
        selected();
         if (Greenfoot.mouseClicked(this)) {
            MenuDijkDoorBraak wereld = (MenuDijkDoorBraak)getWorld();
            int Charselect=wereld.setCharselect(1);
         }
    } 
    public void selected()
    {
        MenuDijkDoorBraak wereld = (MenuDijkDoorBraak)getWorld();
        int Charselect=wereld.getCharselect();
        if(Charselect==1)
        {
            setImage("politie select.png");
        }
        else
        {
            setImage("politie auto.png");
        }
    }
}
i use the value's of 0,1,2(charselect) when i go to the other world with Greenfoot.setWorld(new FloodWorld()) and i use the code
MenuDijkDoorBraak world = (MenuDijkDoorBraak) getWorld();
int charselect=MenuDijkDoorBraak.getCharselect();
i get a error.. MenuDijkDoorBraak cannot be cast in FloodWorld. Someone can help me?
Thellior Thellior

2013/1/11

#
Fixed it already thanks:) With Greenfoot.setWord(newFloodWorld(Menu.DijkDoorBraak.charselect) give a parameter. in FloodWorld. Public FloodWorld(int charselect)
You need to login to post a reply.