Super_Hippo wrote...
I already stated it. If 'getOneObjectAtOffset' returns null, it doesn't mean you don't touch the object when you are moving.


1 2 3 4 5 6 7 8 | 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: 663 ) at greenfoot.Actor.getX(Actor.java: 157 ) at Fireball.act(Fireball.java: 24 ) at greenfoot.core.Simulation.actActor(Simulation.java: 568 ) at greenfoot.core.Simulation.runOneLoop(Simulation.java: 526 ) 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | import greenfoot.*; public class Fireball extends Actor { private int ani = 0 ; //animation variable private int timer = 0 ; private int bounce = 0 ; //bounce counter private boolean onGround; //ground variable public void act() { if (getX() > 954 ){ //somehow atWorldEdge didn't work, no clue why so I had to do this getWorld().removeObject( this ); } dostuff(); if (bounce == 0 ){ //the ball can bounce from a wall once, then if it hits the wall a second time, gets removed. bounce(); setLocation(getX()+ 6 , getY()+ 4 ); } else if (bounce == 1 ){ setLocation(getX()+ 6 , getY()- 4 ); bounce(); } else if (bounce > 1 ){ getWorld().removeObject( this ); } } public void dostuff() { //does stuff animation(); if (timer >= 85 && timer < 90 ){ //despawn animation, when time runs out setImage( "fireball8.png" ); } else if (timer >= 90 && timer < 95 ){ setImage( "fireball9.png" ); } else if (timer >= 95 && timer < 100 ){ setImage( "fireball10.png" ); } ani++; //animation variable +1 timer++; //timer varlable +1 if (timer >= 100 ){ //after a time, the fireball gets removed getWorld().removeObject( this ); } } public void bounce(){ onGround = false ; // for current on ground state Actor ground = getOneIntersectingObject(Ground. class ); //checks if in ground of not if (ground != null ){ //If Fireball is in Ground setLocation(getX()- 5 , getY()- 3 ); bounce++; } } public void animation(){ //animation for left movement if (ani == 0 ){ setImage( "fireball1.png" ); } else if (ani == 8 ){ setImage( "fireball2.png" ); } else if (ani == 16 ){ setImage( "fireball3.png" ); } else if (ani == 24 ){ setImage( "fireball4.png" ); } else if (ani == 32 ){ setImage( "fireball5.png" ); } else if (ani == 40 ){ setImage( "fireball6.png" ); } else if (ani == 48 ){ setImage( "fireball7.png" ); ani = 16 ; } } } |
1 | if (getWorld() == null ) return ; |