Search code examples
objective-cviewpropertiescocos2d-iphonescene

How to pass parameters with replaceScene method in cocos2d?


when i changed view in Cocoa Touch i use this:

GameViewController *game = [self.storyboard instantiateViewControllerWithIdentifier:@"GameViewController"];
game.something = someValue;
game.somethingOther = someOtherValue;

[self presentViewController:game animated:NO completion:^{}];

How can i pass this values before replaceScene?

I've got this now:

[[CCDirector sharedDirector] replaceScene:[CCTransitionFade transitionWithDuration:1.0 scene:[GameLayer scene] withColor:ccWHITE]];

Solution

  • Ok, that was so easy...

    Needed to create method +(CSScene *)sceneWithParameter: and method -(id)initWithParameter:. And in first method need to change ClassLayer *layer = [ClassLayer node] on ClassLayer *layer = [[ClassLayer alloc] initWithParameter:] and it works.