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

2011/12/18

Quick Question

DMCGames DMCGames

2011/12/18

#
How do you remove two Actors in one Actor like:
        if(Greenfoot.mouseClicked(this))
        {
         getWorld().addObject ( new Ground2(), 402, 748);
         getWorld().addObject ( new Ground2(), 850, 748);
         getWorld().addObject ( new Ground(), 450, 433);
         getWorld().addObject ( new SubGround(), 250, 550);
         getWorld().addObject ( new DHealthbar(), 1400, 748);
         getWorld().addObject ( new Bowman(), 89, 608);
         getWorld().addObject ( new Dragonoir(), 1500, 370);
         getWorld().setBackground("BATTLE.png");
         getWorld().removeObject(this);                            
 }      
then you also getWorld().removeObject("Random.class); but, when I do that, it give me an error saying it can't be applied.
Builderboy2005 Builderboy2005

2011/12/18

#
It can't be applied because the arguments to removeObject() need to be an Actor, not a class. In the place of Random.class, put the reference to the object you wan't to remove. Also make sure to do this before you remove yourself, or else you will not be able to access the world.
Duta Duta

2011/12/18

#
DMCGames wrote...
then you also getWorld().removeObject("Random.class);
What builderboy2005 said, and also there is an opening " mark before Random.class, but not one after
DMCGames DMCGames

2011/12/18

#
How do you make a reference? I'm sorry, I am still new to java.
kiarocks kiarocks

2011/12/18

#
you need removeObjects(); use this code:
getWorld().removeObjects(getWorld.getObjects(Random.class));
Reference:
protected void addedToWorld(World world)
{
    this.world = world;
}
DMCGames DMCGames

2011/12/19

#
says that" world is not public in greenfoot.Actor; cannot be accessed by outside package"
danpost danpost

2011/12/19

#
You really do not need the 'Reference' part, just the first line of code kiarocks supplied. But what he meant was:
getWorld().removeObjects(getWorld().getObjects(Random.class));
He missed the '()' after the second 'getWorld' (just an oversite, I'm sure).
DMCGames DMCGames

2011/12/19

#
Thanks for all the help, I got it to work correctly now.Thank you
You need to login to post a reply.