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

Comments for Nyan Cat

Return to Nyan Cat

if(getX() < int || getY() < int || getX() > int || getY() > int) I think this will fix your bullet. the ints are the size of your map just put it in your act method then put under it { getWorld().removeObject(this); }
GriffonGriffon

2012/5/2

I've had this problem several times, I found that the getWorld().removeObject(this); statement has to be the very last statement in the act() method or put an if statement that would be false if it's no longer there, here is the reason, the act() method will always executes all statements in it and you get the error if the actor is gone before the act() method is done here is how I fixed the error: public class Bullet extends SmoothMover { private boolean remove = false; public void act() { movearound(); dissapear(); eatAsteroid(); if(remove) getWorld().removeObject(this); } public void dissapear() { if (atWorldEdge()) { remove = true; } } public void movearound() { move(7.0); } public void eatAsteroid() { if(canSee(Asteroid.class)) { eat(Asteroid.class); remove = true; } } }
danpostdanpost

2012/5/3

I fixed by just changing 'eatAsteroid();' to 'if (getWorld != null) eatAsteroid();'.
danpostdanpost

2012/5/3

Sorry, that was supposed to be: if (getWorld() != null) eatAsteroid();
DutaDuta

2012/5/3

Also: public void act() { if(condition) { getWorld().removeObject(this); return; } //Any code here won't raise errors if the actor is removed, because the code exits out of the method through the return statement. }
solo1512solo1512

2012/5/3

Have the rocks kill nyan cat. public void killNyanCat(Class clss) Actor actor = getOneObjectAtOffset(0,0,clss); if(actor != null) { getWorld().removeObject(actor); } this is the method signature: killNyanCat(NyanCat.class);
solo1512solo1512

2012/5/3

Fix that bug cuz when it goes into the upper righthand corner it pauses the application!
A new version of this scenario was uploaded on Thu May 03 23:33:12 UTC 2012 Fixed error, Thanks everyone for responding so quickly. :)
A new version of this scenario was uploaded on Thu May 03 23:34:04 UTC 2012 Fixed error, Thanks everyone for responding so quickly. :)
davecoolkiddavecoolkid

2012/5/3

Thanks everyone, I fixed the error :)
A new version of this scenario was uploaded on Thu May 03 23:35:18 UTC 2012 Fixed error, Thanks everyone for responding so quickly. :)