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

2013/6/1

Passing variables from world to actor.

welleid welleid

2013/6/1

#
Hey again, i'm dealing with an issue. I have a World called IG, which extends another one. Now, in this IG, i set levels of my game that way :
 public void act()
    {
         int nbrBlocs = getObjects(Bloc.class).size(); //On récupère le nombre de blocs présents dans le monde
         
         if(nbrBlocs == 0) //Si il y a plus de blocs
         {
             if(level == 1) //Si on était au niveau 1
             {
                 level = 2; //On passe au niveau 2
                 niveau2();
             }
             
             if(level == 2)
             {
                 level = 3;
                 niveau3();
             }
         }
    }
I then set functions like level3() in which i set the actors. Now, when you play the game, some objects apperar and disappear with the getWorld().addObject(...) or removeObject(...) The thing is, at a moment, One object appear with getWorld().addObject(megaroue); It's not said in the IG world, it's in an actor class. Now, it's supposed to stay until level 3. That's why, in level3, I want to remove it. Basically it should be from IG (World), something like that : public void level3() { removeObject(megaroue); } The object class i want to remove is called Megaroue.class But i dont know how to access this actor from the world, as it appeared through a getWorld().addObject().
danpost danpost

2013/6/1

#
removeObjects(getObjects(Megaroue.class)) The World class method 'getObjects' returns a list of all objects of the given class in the world (or all object of every class in the world, if 'null' was used for the class). 'removeObjects' is another World class method which takes a list of objects that are to be removed from the world.
You need to login to post a reply.