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

2012/6/24

Problems using multiple worlds!

Zamoht Zamoht

2012/6/24

#
As the title says I'm having trouble using two worlds. I'm changing between two worlds (with the exact same code, and the only difference is the size), and the problem is that I'm using the same actors for both worlds, so the actor's method only works for one of the levels, when I use methods like this:
public void die()
    {
        ((Puzzle) getWorld()).resetLevel();
    }
The other world is called Puzzle2, which means that this method will call a world that doesn't exist (when Puzzle2 is active). Is there an easy way to fix this or do I have to create a new actor with the exact same code and just change this one method to:
public void die()
    {
        ((Puzzle2) getWorld()).resetLevel();
    }
This would be easy, but it would require more space. (I have 5 actors with the same problem, just to point out that this fix would require some space)
erdelf erdelf

2012/6/24

#
public void die()
{
    World world = getWorld();  
    if(world instanceof Puzzle)  
    {  
         world = (Puzzle) getWorld();
    } else if(world instanceof Puzzle2)  
    {  
         world = (Puzzle2) getWorld();
    } 
    world.resetLevel(); 
}
try this
Zamoht Zamoht

2012/6/24

#
Thank you very much! I changed the code a little:
public void die()  
    {  
        World world = getWorld();    
        if(world instanceof Puzzle)    
        {    
            ((Puzzle) getWorld()).resetLevel();  
        } 
        else if(world instanceof Puzzle2)    
        {    
            ((Puzzle2) getWorld()).resetLevel();  
        }   
    }  
since 'world.resetLevel();' didn't work.
You need to login to post a reply.