here is my code on bullet
it give 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."
and i want when we hit the enemy, enemy's hp - 1 and when enemy hp = 0 it removed
code on enemy
Thanks for helping
public void act() { // Add your action code here. setRotation(direction); move(speed); if (isAtEdge()){ getWorld().removeObject(this); }else{ hittingEnemy (); //error here } } private void hittingEnemy (){ if (isTouching (Enemy.class)){ getWorld().addObject(new Boom(), getX(), getY()); getWorld().removeObject(this); removeTouching(Enemy.class); //and here MyWorld.setScore(10); } }
//private static int Ehp = 2; public static void setEhp(int dmg){ Ehp = Ehp + dmg; } public void die(){ if ( Ehp < 1 ){ getWorld().removeObject(this); } }