If you're going to be passing around the score to a lot of different scenes, you might want to store it in NSUserDefaults
or some accessible storage mechanism. However, if you're looking to pass data between SpriteKit objects, every SKNode
(including SKScene
) has a dictionary property called userData
that you can use for whatever you so desire. Here's an example of how you might pass the score between scenes:
- (void)changeScene
{
SKView *spriteView = (SKView *) self.view;
SKScene *currentScene = [spriteView scene];
SKScene *newScene = [MySceneClass scene];
[newScene.userData setObject:[currentScene.userData objectForKey:@"score"] forKey:@"score"];
[spriteView presentScene:newScene];
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…