So I have an DamageActor that will move for a specific amount of time, and then remove itself from the world. However, I can't see to figure that out. I followed the information on this discussion: http://www.greenfoot.org/topics/1462 but it didn't seem to work.
Here's my code:
I keep getting a NullPointerException.
Other note: I'm testing my code using a DamageActor subclass.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | public void act() { if (getWorld() == null ) return ; if (isFlipped) moveLeft(); else moveRight(); update(); } public void update() { myDistance--; if (myDistance <= 0 ) { removeSelf(); return ; } } public void removeSelf() { myWorld.removeObject( this ); } |