How can I delay just one object (not the entire program with Greenfoot.delay())? I have a parent class and then four subclasses that will all use this delay method at some point.


1 2 3 4 | public void act() { if (delay) return ; // if some delay boolean is true, exit method ... } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | // field int delayTimer; // act method public void act() { if (delay > 0 && --delay > 0 ) return ; // do nothing if delaying // if (<< some condition >>) { delay = 180 ; // initiate delay // other actions } // } |
1 2 3 4 5 | if (delay > 0 ) { if (--delay == 0 ) getWorld().removeObject( this ); return ; } |
1 2 3 4 5 6 | public void removeDelay() { int delayTime = 1000 ; while (delayTime > 0 ) delayTime--; if (delayTime == 0 ) getWorld().removeObject( this ); } |
1 2 3 4 5 6 | public void removeDelay() { int delayTime = 1000 ; while (delayTime > 0 ) delayTime--; if (delayTime == 0 ) getWorld().removeObject( this ); } |
1 2 3 4 | public void removeDelay() { getWorld().removeObject( this ); } |