First you will need to create a method to call with this parameter
HelloWorldLayer.h
@interface HelloWorldLayer : CCLayer { } +(CCScene *)sceneWithParam:(id)parameter; @end
HelloWorldLayer.m
@implementation HelloWorldLayer +(CCScene *)sceneWithParam:(id)parameter { [[parameter retain]doSomething]; CCScene * scene = [CCScene node]; HelloWorldLayer *layer = [HelloWorldLayer node]; [scene addChild: layer]; return scene; } -(id) init { if(self = [super init]) { } return [super init]; }
Then you push it, calling
[[CCDirector sharedDirector] pushScene:[HelloWorldLayer sceneWithParam:obj]];
Now this may not be enough, if you need a parameter inside your layer, you will need to do the same for the layer. Create an initmethod using the method, and then pass it further to the layer in the sceneWithParam: method.
source share