I have a problem! I try to programm a game for school. In my game there is a tank which can fire missles. I make a Object at the location of the missle with
getWorld().addObject ( new Smoke(), getX(), getY());
The missle should also remove at the Edge of the World and when it hits a brickwall. But every time a missle hits a brickwall theres an error and I don't know why! But the error is in contact with the AtWorldEdge method
Error:
java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed.
at greenfoot.Actor.failIfNotInWorld(Actor.java:681)
at greenfoot.Actor.getX(Actor.java:157)
at schuss1.AtWorldEdge(schuss1.java:33)
at schuss1.act(schuss1.java:18)
at greenfoot.core.Simulation.actActor(Simulation.java:583)
at greenfoot.core.Simulation.runOneLoop(Simulation.java:541)
at greenfoot.core.Simulation.runContent(Simulation.java:215)
at greenfoot.core.Simulation.run(Simulation.java:205)
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 26 27 28 29 30 | private void makeSmoke() //setzt Rauch an Position von Schuss { count--; if (count == 0 ) { //wenn count null ist, sonst ist zuviel Rauch da getWorld().addObject ( new Smoke(), getX(), getY()); count = 2 ; // setzt count wieder auf zwei } } private void AtWorldEdge() { if (getX() < 10 || getX() > 1590 || getY() < 10 || getY() > 790 ) { getWorld().removeObject( this ); count = 2 ; } } private void checkWall() { Actor brickwall = getOneIntersectingObject(brickwall. class ); if (brickwall != null ) { getWorld().removeObject(brickwall); getWorld().removeObject( this ); Greenfoot.playSound( "hit.wav" ); count = 2 ; } } |