The object of below actor class touches object of class EnemyA or EnemyB. After adding the code in the act method, the checkCollision() method is working only for the first collision. Later it works only for intermittent collisions (skips some objects after first collision)
Note: touch() method returns true if the collision happens.
public void act()
{
checkCollision();
if(delay>0){
if(delay%2==0){
turn(moveOffset);
moveOffset = -6;
}else{
turn(moveOffset);
moveOffset = 6;
}
initialOffset-=moveOffset;
delay--;
}
}
public void checkCollision() {
if(touch(EnemyB.class) || touch(EnemyA.class)) {
Actor touched = getOneIntersectingObject(Actor.class);
this.touchedClassName = touched.getClass().getName();
getWorld().removeObject(touched);
if(touchedClassName.equals("EnemyA"))
{
getWorld().removeObject(touched);
if(delay==0)
delay = 20;
}
}
}
