I am creating a game with SpriteKit and trying to increase the score in a collision. For some odd reason, every time the count increases, this random number is not only 1.
In the method didBeginContact, I have a collision between a bullet and an alien. Every time I came across, I would like the score to increase the score by 1. Except that he has his own mind and will randomly increase it by a number from 1 to 6. I went through each line of code and tried to add by scoring in the game several times, but it just does not increase by 1, as I would like. At the moment, my code is as follows.
In my header file, I create a property to evaluate:
@property (nonatomic) int score;
Then in my main game scene I add the following
-(void)setScore:(int)score
{
_score = score;
_scoreLabel.text = [NSString stringWithFormat:@"%d", score];
}
init , 0
self.score = 0;
, ββ 0
self.score = 0;
. self.score ++;
if (firstBody.categoryBitMask == kAlienCategory && secondBody.categoryBitMask == kBulletCategory) {
self.score++;
if (firstBody.node) {
[self alienExplosion:firstBody.node.position];
[firstBody.node removeFromParent];
}
if (secondBody.node) {
[self bulletExplosion:secondBody.node.position];
[secondBody.node removeFromParent];
}
}
UPDATE: NSLog, , . , 1 - 6. 6, 1

