I pretty much have the same question as this one. But it doesn't explain how to retrieve the score from the dictionary. I want to pass a float called score to another scene.
I have the following code in my update method:
if (lives == 0) {
SKScene * nextScene = [[GameOverScene alloc] initWithSize:self.size];
nextScene.userData = [NSMutableDictionary dictionary];
NSNumber * scoreForDictionary = [NSNumber numberWithFloat:score];
[nextScene.userData setObject:scoreForDictionary forKey:@"score"];
[self.view presentScene:nextScene];
}
I have this code in the other scene:
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
NSNumber * scoreNumber = [self.view.scene.userData objectForKey:@"score"];
score = [scoreNumber floatValue];
[self showScore];
}
return self;
}
I think this is the way to do it, but it doesn't work. Can you please explain how to pass a float to another scene?