Skip to main content

iphone - Cocos2d score resetting is messing up (long post warning) -


the score not resetting right @ all,i trying make high score counter every time passed previous high score update.however, right resetting during game. example if had high score of 2 during game take 3 points put 3 high score instead of keep going until game over. have came conclusion need reset in gameoverlayer won't reset during game. have been trying to no luck.

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

same code .h file hello world (my game) except no _score=0; hoping reset score in game on layer instead keeps going now

iphone - cocos2d score resetting messing (long post warning) - stack overflow

learn, share, build

each month, on 50 million developers come stack overflow learn, share knowledge, , build careers.

join world’s largest developer community.

sign up

the score not resetting right @ all,i trying make high score counter every time passed previous high score update.however, right resetting during game. example if had high score of 2 during game take 3 points put 3 high score instead of keep going until game over. have came conclusion need reset in gameoverlayer won't reset during game. have been trying to no luck.

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

same code .h file hello world (my game) except no _score=0; hoping reset score in game on layer instead keeps going now

share|improve question
    
can clean code little? spacing far apart. – john riselvato jul 7 '12 @ 15:02
    
thats i'm trying lol. – jhon doe jul 7 '12 @ 15:04
    
ok, should easier read. if need explaining feel free ask. need figure out how reset score in game on scene stop resetting in middle of game. – jhon doe jul 7 '12 @ 15:13
    
also, believe need put _score= 0; @ spot because resets all. – jhon doe jul 7 '12 @ 15:24
    
first, check if have display problem (label not updated correctly) or if actual score variable being reset. add breakpoint , modify condition halt app when variable 0. should narrow down. – learncocos2d jul 7 '12 @ 17:52

your answer

 
discard

posting answer, agree privacy policy , terms of service.

browse other questions tagged or ask own question.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -