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

2013/5/18

How to solve it: java.lang.IllegalStateException: Actor not in world.

Miikku Miikku

2013/5/18

#
Actor not in world can someone help? Here is my code: import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Bullet extends Actor { private boolean getAngle = true; public void act() { angleSelect(); move(10); remove(); } public void remove() { if(getX() >= getWorld().getWidth() -1) getWorld().removeObject(this); else if(getX() <= 1) getWorld().removeObject(this); else if(getX() >= getWorld().getHeight() -1) getWorld().removeObject(this); else if(getX() <= 1) getWorld().removeObject(this); } public void angleSelect() { if(getAngle == true) { setRotation(Soldier.currentRot); getAngle = false; } } public void kill() { Actor zombie; zombie = getOneObjectAtOffset(0, 0, Zombie.class); if (zombie != null) { World world; world = getWorld(); world.removeObject(zombie); } } }
danpost danpost

2013/5/18

#
I do not know if this will help (being you did not specify where the error occurred; or supplied the whole error message), but try this: (1) remove the instance field declaration: private boolean getAngle = true; (2) remove the following statement from the act method: angleSelect(); (3) remove the 'angleSelect' method entirely (4) add the following Bullet constructor
public Bullet()
{
    setRotation(Soldier.currentRot);
}
Miikku Miikku

2013/5/18

#
Ok I try it :)
Miikku Miikku

2013/5/18

#
It works! :) Thanks for help!
You need to login to post a reply.