iphone - How to set high score and only changes if it is surpassed -


like game helicopter or left 4 dead survival mode want score stay , change if score surpassed. here code have far. ./m file

                    _score = 0;                          _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]];    } 

and .h file

       int _score; int _oldscore; cclabelttf *_scorelabel; 

i tried put

      _score = [[nsuserdefaults standarduserdefaults] integerforkey:@"score"];          [[nsuserdefaults standarduserdefaults] setinteger:_oldscore forkey:@"score"];            [[nsuserdefaults standarduserdefaults] synchronize];         

but when did saved data , keeps going rather starting on , change when score surpassed.

you need compare if score more old score , save then.

for example,

if (_score > _oldscore) {   // save out new score more old score    // reset ready next time   _oldscore = _score;   _score = 0; } 

however, if struggling this, suggest going in whole lot of problems unless stop , learn basics of programming before progressing further in development.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -