help when is use code remove object my world stops. the error say the actor where i am asking location isn't in world.
i use this code
import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)
/**
* A bullet that can hit bal.
*
*
*/
public class Bullet extends Mover
{
/** A bullet looses one life each act, and will disappear when life = 0 */
private int life = 75;
private int setnumber;
/** The damage this bullet will deal */
private int damage = 16;
/**
public Bullet()
{
}
*/
public Bullet(Vector speed, int rotation)
{
super(speed);
setRotation(rotation);
increaseSpeed(new Vector(rotation, 35));
/**
Greenfoot.playSound("EnergyGun.wav");
*/
}
/**
* The bullet will damage Body if it hits them.
*/
public void act()
{
if(life <= 0) {
}
else {
move();
Ball Ball = (Ball) getOneIntersectingObject(Ball.class);
if(Ball != null){
getWorld().addObject(new Ball2(), getX(), getY());
getWorld().addObject(new Ball2(), getX(), getY());
getWorld().removeObject(Ball);
getWorld().removeObject(this);
}
else {
life--;
}
Ball2 Ball2 = (Ball2) getOneIntersectingObject(Ball2.class);
if(Ball2 != null){
getWorld().addObject(new Ball3(), getX(), getY());
getWorld().addObject(new Ball3(), getX(), getY());
getWorld().removeObject(Ball2);
getWorld().removeObject(this);
}
else {
life--;
}
Ball3 Ball3 = (Ball3) getOneIntersectingObject(Ball3.class);
if(Ball3 != null){
getWorld().addObject(new Ball4(), getX(), getY());
getWorld().addObject(new Ball4(), getX(), getY());
getWorld().removeObject(Ball3);
getWorld().removeObject(this);
}
else {
life--;
}
Ball4 Ball4 = (Ball4) getOneIntersectingObject(Ball4.class);
if(Ball4 != null){
getWorld().addObject(new Ball5(), getX(), getY());
getWorld().addObject(new Ball5(), getX(), getY());
getWorld().removeObject(Ball4);
getWorld().removeObject(this);
}
else {
life--;
}
Ball5 Ball5 = (Ball5) getOneIntersectingObject(Ball5.class);
if(Ball5 != null){
getWorld().removeObject(Ball5);
getWorld().removeObject(this);
}
else {
life--;
}
}
checkCollision();
}
/**
* Check whether we are colliding with Obstacle.
*/
private void checkCollision()
{
Obstacle a = (Obstacle) getOneIntersectingObject(Obstacle.class);
if(a != null) {
getWorld().removeObject(this);
}
}
/**
* Check whether we are colliding with Obstacle2.
private void checkCollision()
{
Obstacle2 a = (Obstacle2) getOneIntersectingObject(Obstacle2.class);
if(a != null) {
getWorld().removeObject(this);
}
}
*/
}