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

2017/1/4

Removing two Actors after Intersection

ShadowSamurai ShadowSamurai

2017/1/4

#
I have two Actors : An Enemy and a bullet class. My problem is that only one actor can be removed, the other is still in World. I used the if (getOneIntersectingObject(---); method for both but it doesn't work. I hope that someone can help me :)
Super_Hippo Super_Hippo

2017/1/4

#
You can use this in the Bullet's act method:
if (isTouching(Enemy.class))
{
    removeTouching(Enemy.class);
    getWorld().removeObject(this);
}
danpost danpost

2017/1/4

#
An actor does not consider itself as an intersecting object. However, you can refer to it as 'this':
// in Enemy class
if (isTouching(Bullet.class))
{
    removeTouching(Bullet.class);
    getWorld().removeObject(this);
}
You need to login to post a reply.