objective c - Sprite Kit: How to pass scores between different scene? -


i stuck trying pass score between 2 scenes, myscene, , mymenu. game part score changes declared _score(nsinteger), , label _scorelabelnode(sklabelnode) code used initalize label, , create label holds score in myscene is

_score = 0; _scorelabelnode = sklabelnode labelnodewithfontnamed:@"markerfelt-wide; _scorelabelnode.position =cgpointmake (cgrectgetmidx(self.frame), 3 *self.frame.size.height /4); _scorelabelnode.zposition = 100; _scorelabelnode.text = [nsstring stringwithformat:@"%d",_score]; _scorelabelnode.fontcolor =[uicolor blackcolor]; [self addchild:_scorelabelnode] 

so guess question is, how transfer score between 2 scenes when score needs change in myscene, , needs show score user got in mymenu. in advance.

ps:i'm learning code appreciate detailed response

use nsuserdefaults in myscene:

nsuserdefaults *prefs = [nsuserdefaults standarduserdefaults]; [prefs setinteger:_score forkey:@"score"]; 

and in mymenu:

nsuserdefaults *prefs = [nsuserdefaults standarduserdefaults]; int score = [prefs integerforkey:@"score"]; sklabelnode *scorelabel = [sklabelnode labelnodewithfontnamed:@"markerfelt-wide"]; //other label node configuration here scorelabel.text = [nsstring stringwithformat:@"%d",score] //other configuration here 

this might not quite right, wrote off top of head. xcode fix warnings/errors.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -