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

2013/3/30

Is it possible to have an object delete itself?

BubbaB BubbaB

2013/3/30

#
So I want a bullet to be shot and when its y cord is equal to 0 I want it to disappear. Here is my bullet class. import greenfoot.*; /** * Write a description of class Bullet here. * * @author (your name) * @version (a version number or a date) */ public class Bullet extends Actor { /** * Act - do whatever the Bullet wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { move(5); if(getY() == 0) { //Code to remove itself here. } } public Bullet() { setRotation(-90); } } So how could I do this?
Gevater_Tod4711 Gevater_Tod4711

2013/3/30

#
the code which tells an object that it has to remove itself is: getWorld().removeObject(this);
BubbaB BubbaB

2013/3/30

#
Ah! That makes total sense! Thank you!
You need to login to post a reply.