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

2017/5/27

Remove an actor from the World class

JonahZW JonahZW

2017/5/27

#
Hello, I'm trying to remove an actor from the world, and this has to get called through the world class. When I just use "removeObject(myBall);," nothing happens. I know the method is getting called, because it has done other things, like add an actor. Any help is appreciated, thank you!
danpost danpost

2017/5/28

#
No code given. Cannot tell what 'myBall' refers to (if anything). Show world class code.
JonahZW JonahZW

2017/5/28

#
Sorry, here's the code:
public class Board extends World
{
    Ball myBall;
    LevelPass LevelPass;

    /**
     * Constructor for objects of class Level1.
     * 
     */
    public Board()
    {    
        super(460, 460, 1);
    }
     /**
     * After all bricks are destroyed, sends to level two.
     */
    public void levelTwo()
    {
        blocksDestroyed = blocksDestroyed + 1;

        if (blocksDestroyed == 2)
        {
            myBall.endLevel();
            addObject(new LevelPass(), 230, 230);
            //removeObject(myBall);
            //myBall.removeBall();
            //Greenfoot.setWorld(new Board2());

            //myBall.setLocation(230, 230);
        }
    }
}
The things in quotes are different things that I tried, but didn't work. Thank you!
danpost danpost

2017/5/28

#
There is no code to add a ball into the world (nor created). So 'myBall' is never assigned any Ball object that can be removed.
You need to login to post a reply.