The score is not resetting right at all,I am trying to make a high score counter where every time you passed previous high score it will update.However, the score just keep going up without resetting even after game over I want the high score to be up until it is surpassed. I tried resetting the score in the game over layer but no good it would seem.
gameover .m
CGSize winSize = [[CCDirector sharedDirector] winSize];
_score = [[NSUserDefaults standardUserDefaults] integerForKey:@"score"];
_oldScore = -1;
self.scoreLabel = [CCLabelTTF labelWithString:@"" dimensions:CGSizeMake(100, 50) alignment:UITextAlignmentRight fontName:@"Marker Felt" fontSize:32];
_scoreLabel.position = ccp(winSize.width - _scoreLabel.contentSize.width, _scoreLabel.contentSize.height);
_scoreLabel.color = ccc3(255,0,0);
[self addChild:_scoreLabel z:1];
if (_score > _oldScore) {
_oldScore = _score;
[_scoreLabel setString:[NSString stringWithFormat:@"score%d", _score]];
[[NSUserDefaults standardUserDefaults] setInteger:_oldScore forKey:@"score"];
. m hello world file (the game file)
CGSize winSize = [[CCDirector sharedDirector] winSize];
_score = [[NSUserDefaults standardUserDefaults] integerForKey:@"score"];
_oldScore = -1;
self.scoreLabel = [CCLabelTTF labelWithString:@"" dimensions:CGSizeMake(100, 50) alignment:UITextAlignmentRight fontName:@"Marker Felt" fontSize:32];
_scoreLabel.position = ccp(winSize.width - _scoreLabel.contentSize.width, _scoreLabel.contentSize.height);
_scoreLabel.color = ccc3(255,0,0);
[self addChild:_scoreLabel z:1];
if (_score > _oldScore) {
_oldScore = _score;
[_scoreLabel setString:[NSString stringWithFormat:@"score%d", _score]];
[[NSUserDefaults standardUserDefaults] setInteger:_oldScore forKey:@"score"];
_score =0;
the score however just keeps going up. I want the high score to stay until it surpassed
1 Answer