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

2017/2/24

Remove an actor

Fifilein Fifilein

2017/2/24

#
Hi! It's me again.I don't understand why my code for my game doesn't work.In my game there are two actors called Frosch and Snake.I want the snake to eat the Frosch and after the snake eats the frog to show a gamover and tryagain text and remove the snake too.I tried this code in the snake class
 Actor getFrosch = getOneIntersectingObject (Frosch.class);
     if (getFrosch != null)
     {
         World myWorld = getWorld();
         GameOver gameover = new GameOver();
        myWorld.addObject(gameover, myWorld.getWidth()/2, myWorld.getHeight()/2);
        TryAgain tryagain = new TryAgain();
        myWorld.addObject(tryagain, 300, 300);
        myWorld.removeObject(getFrosch);
        myWorld.removeObject(this);  
        }
But my problem is that the snake doesn't disappear. Could you please help me? I'm just a beginner in greenfoot. Thank you! Fifilein
Super_Hippo Super_Hippo

2017/2/24

#
Does the frog disappear?
Fifilein Fifilein

2017/2/24

#
Yes,Everything works except the snake
Super_Hippo Super_Hippo

2017/2/24

#
Did you add the last line at last? Did it compile this step? (Sometimes the auto-compile does not do what it should.) Try to close and restart your project and report back if anything changed. If not, post your Snake class code.
danpost danpost

2017/2/24

#
What code are you using to add the snake into the world and where is it located? (show as much code as needed)
You need to login to post a reply.