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

2020/2/27

How do I delay a line of code?

footpickle footpickle

2020/2/27

#
So I'm trying to make a bomb explode (with the setImage method) before it disappears, but it doesn't. is there a way to delay the line of code removing the bomb from the world?
danpost danpost

2020/2/27

#
footpickle wrote...
So I'm trying to make a bomb explode (with the setImage method) before it disappears, but it doesn't. is there a way to delay the line of code removing the bomb from the world?
What you should do is create a different actor for the explosion. Add it into the world just before removing the bomb at the bombs location.
footpickle footpickle

2020/2/27

#
danpost wrote...
footpickle wrote...
So I'm trying to make a bomb explode (with the setImage method) before it disappears, but it doesn't. is there a way to delay the line of code removing the bomb from the world?
What you should do is create a different actor for the explosion. Add it into the world just before removing the bomb at the bombs location.
GENIUS!
footpickle footpickle

2020/2/27

#
Um... How would I do that, exactly?
danpost danpost

2020/2/27

#
footpickle wrote...
Um... How would I do that, exactly?
Move explosion code into new class (subclass of Actor, maybe called BombExplosion).
footpickle footpickle

2020/2/27

#
But how would I create it where the bomb last was, and at the right time? is there a getPosition method? does that exist? I'm very new to greenfoot, so I have pretty much NO idea what I'm doing.
danpost danpost

2020/2/27

#
footpickle wrote...
But how would I create it where the bomb last was, and at the right time? is there a getPosition method? does that exist? I'm very new to greenfoot, so I have pretty much NO idea what I'm doing.
I wrote:
Add it into the world just before removing the bomb at the bombs location.
Where are you removing the bomb? In the Bomb class. The bomb's location is quite accessible there also.
footpickle footpickle

2020/2/27

#
I found out another solution, but it now disables the feature that removes the bomb when it runs out of life out goes off the edge of the world. all it does is changes the image, I have no idea why it would make the bomb exist longer
You need to login to post a reply.