How to make objects check in SpriteKit to count the score ;

for (SKNode * drug1 in [self.droppingdrug1 copy ]){ if (CGRectContainsRect(self.car.frame, drug1.frame)){ [drug1 removeFromParent]; self.score++; [self.droppingdrug1 removeObject:drug1]; 

There is an increase in points, but how to make it so that if the car doesn’t catch it - it takes away points?

    1 answer 1

    Come up with some condition in which the object is considered to be missed, for example, when it leaves the screen, remove it from the array of objects and take away points.

     if (CGRectContainsRect(self.car.frame, drug1.frame)){ [drug1 removeFromParent]; self.score++; [self.droppingdrug1 removeObject:drug1]; } else if !(CGRectContainsRect(self.gameArea.frame, drug1.frame)) { [drug1 removeFromParent]; self.score--; [self.droppingdrug1 removeObject:drug1]; }