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

2020/3/6

Help!

Muurc Muurc

2020/3/6

#
I'm an absolute noob in greenfoot and I'm learning it in school since 3 months or so. I have a scenario, where I want a driving object to drive on a button which activates a bomb which explodes. When the bomb explodes, all objects around the bomb have be destroyed and removed from the world. I managed to get the bomb activated. The only problem is, that I don't know how to get the bomb to remove objects around it only when the driving object hits the button. In my case the bomb immediately removes the objects before everything else start to move. I have to teach the bomb to remove the objects only when the button is hit. Can someone help me? ("Run" Button isn't allowed, only "Act")
danpost danpost

2020/3/6

#
Muurc wrote...
I want a driving object to drive on a button which activates a bomb which explodes. When the bomb explodes, all objects around the bomb have be destroyed and removed from the world. I managed to get the bomb activated. The only problem is, that I don't know how to get the bomb to remove objects around it only when the driving object hits the button. In my case the bomb immediately removes the objects before everything else start to move. I have to teach the bomb to remove the objects only when the button is hit.
You can add an addedToWorld method for the bombs. It is called automatically by greenfoot when the object is placed into a world (and only then). There, you can get the objectsInRange and remove them. The method starts with:
protected void addedToWorld(World world)
where world is a reference to the world the actor was added into.
You need to login to post a reply.