分数根本没有重置,我正在尝试制作一个高分计数器,每次你通过以前的高分时它都会更新。但是,即使在比赛结束后分数也会继续上升而不重置我想要高分直到被超越。我尝试在游戏中重设分数,但似乎没有什么好处。
游戏结束.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 文件(游戏文件)
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;
然而,分数一直在上升。我希望高分一直保持到超过