如何在cocos2d中使用replaceScene方法传递参数?

时间:2013-01-03 16:01:17

标签: objective-c view properties cocos2d-iphone scene

当我在Cocoa Touch中更改视图时,我使用此:

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

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

如何在replaceScene之前传递此值?

我现在有了这个:

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

1 个答案:

答案 0 :(得分:4)

好的,那太容易了......

需要创建方法+(CSScene *)sceneWithParameter:和方法-(id)initWithParameter:。在第一种方法中,需要在ClassLayer *layer = [ClassLayer node]上更改ClassLayer *layer = [[ClassLayer alloc] initWithParameter:],然后才能正常工作。