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

2018/11/2

I get an error message every time the rocket hits an asteroid. Does anybody know what the problem is?

Cheerioman25 Cheerioman25

2018/11/2

#
private void checkCollision()
    {
        Asteroid a = (Asteroid) getOneIntersectingObject(Asteroid.class);
        if (a !=null)
        {
            Space space = (Space) getWorld();
            space.removeObject(this);
            space.addObject(new Explosion(), getX(), getY());
            space.gameOver();
        }
    }
danpost danpost

2018/11/2

#
Cheerioman25 wrote...
I get an error message every time the rocket hits an asteroid. Does anybody know what the problem is?
The actor loses its location in the world when you remove it from the world. Add the explosion before removing the actor from the world.
You need to login to post a reply.