2012-06-27 129 views
0

我試着讓我的高分建立起來,如果高分被超過,它會出現在高分中,我有一些想法,但現在只要高分超過它將採取相同數量的高分積分上升一分。例如,每擊殺一個得分,如果高分爲7分,則在高分評分板上需要多殺7分才能達到8分。一旦你獲得高分並且在高分中獲得相同數量的分數就會上升一次,分數就會重新設置。希望它是有道理的。cocos2d高分它搞砸了

這裏是代碼

.h文件中

int _score; 
    int _oldScore; 
    CCLabelTTF *_scoreLabel; 
    @property (nonatomic, assign) CCLabelTTF *scoreLabel; 

.m文件

 _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"]; 

    [[NSUserDefaults standardUserDefaults] synchronize];   


     _score = 0;   

} 

    } 

現在我知道_score = 0;讓董事會休息,但只要你得到高分,它就會一直重置。另一個例子是,如果你在高分榜上得到12分,那麼在高分中將會有24分的殺戮值上升到13分。

還有一件事,如果我拿出_score = 0;得分將保持堆疊,但不會重新開始。

+0

我沒有看到你的結束大括號,因此很難說什麼邏輯在做什麼。你可以在底部添加幾行代碼,這樣我可以看到if語句何時終止? – EdFred

+0

只有兩個花括號,全是 –

回答

1

我不明白這些行:

_score = [[NSUserDefaults standardUserDefaults] integerForKey:@"score"];   
_oldScore = -1; 

不應[[NSUserDefaults standardUserDefaults] integerForKey:@"score"]是舊賬? 以及爲什麼您將_oldScore設置爲-1?

也許我錯過了一些東西...

+0

ns userdefualts將代碼保存爲舊得分,-1不需要誠實 –

+0

是的,但我認爲_oldScore是從NSUserDefaults中檢索的。你在那裏存儲最新的最高分,然後與當前的分數進行比較...... – sergio

+0

那麼我應該怎麼做' –