【发布时间】:2012-07-07 18:58:08
【问题描述】:
分数根本没有正确重置,我正在尝试制作一个高分计数器,每次你通过上一个高分时它都会更新。但是,即使在比赛结束后分数也会继续上升而不会重置我想要高分一直到被超越为止。我尝试在游戏中重设分数,但似乎没有什么好处。
游戏结束.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;
但是分数一直在上升。我希望高分一直保持到超过
【问题讨论】:
标签: iphone ios5 xcode4 cocos2d-iphone