ios - The SKScene recognizes the high score of the GameScene -


i want skscene (medalscene) recognizes high score of gamescene because if high score example "20" appear medal. how can that?

my code in gamescene high score:

nsuserdefaults *ud = [nsuserdefaults standarduserdefaults]; [ud setobject:[nsstring stringwithformat:@"%d",_score] forkey:score_over];  int scorestring=[[ud objectforkey:best_score] intvalue]; if(scorestring < _score){     [ud setobject:[nsstring stringwithformat:@"%d",_score] forkey:best_score];     scorestring = _score; 

and code of medalscene medals:

if(scorestring >= 20){     skspritenode *medal1 = [skspritenode spritenodewithimagenamed:@"medal_1"];     medal1.position = cgpointmake(cgrectgetmaxx( self.frame )*1/4 + 8, cgrectgetmidy(self.frame) + 21);     [self addchild:medal1]; } 

my gamescene shows gameover score high score. , codes:

-(void)showgameover{  nsuserdefaults *hud = [nsuserdefaults standarduserdefaults]; [hud setobject:[nsstring stringwithformat:@"%d",_score] forkey:score_over];  int scorestring = [[hud objectforkey:best_score] intvalue]; if(scorestring < _score){     [hud setobject:[nsstring stringwithformat:@"%d",_score] forkey:best_score];     scorestring = _score;  sklabelnode *lbover = [sklabelnode labelnodewithfontnamed:@"walibi0615"]; lbover.position = cgpointmake(cgrectgetmaxx(self.frame)*3/4, cgrectgetmidy(self.frame)+33); lbover.zposition = 1; lbover.fontsize = 20; lbover.fontcolor = [uicolor blackcolor]; lbover.text = [nsstring stringwithformat:@"%d", _score]; [_gameover addchild:lbover];  sklabelnode *lbmaxover = [sklabelnode labelnodewithfontnamed:@"walibi0615"]; lbmaxover.position = cgpointmake(cgrectgetmaxx(self.frame)*3/4, cgrectgetmidy(self.frame)-14); lbmaxover.zposition = 1; lbmaxover.fontsize = 20; lbmaxover.fontcolor = [uicolor blackcolor]; lbmaxover.text = [nsstring stringwithformat:@"%d", scorestring]; [_gameover addchild:lbmaxover]; } 

i have created second scene (medalscene) , scene should recognize scorestring of gamescene because if example, high score equal 20 appear medal in scene.

and code medal (medalscene):

if(scorestring >= 20){ skspritenode *medal1 = [skspritenode spritenodewithimagenamed:@"medal_1"]; medal1.position = cgpointmake(cgrectgetmaxx( self.frame )*1/4 + 8, cgrectgetmidy(self.frame) + 21); [self addchild:medal1]; } 

i hope clear mean. thank in advance help! :)

you should synchronize userdefaults after set them.

[ud synchronize]; 

i'd use real integers inside userdefaults though (i.s.o. hand-converting strings), like

nsinteger score = [ud integerforkey:best_score]; if (_score > score)  {     [ud setinteger:_score forkey:best_score];     [ud synchronize]; } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -