[英]COCOS 2D iPhone - Parsing variable between scenes and using in layer
I have the code of calling a new scene with the variable: 我有使用变量调用新场景的代码:
[[CCDirector sharedDirector] replaceScene:[GameScene sceneWithParam:item.tag]];
In GameScene.h 在GameScene.h中
@interface GameScene : CCLayer {
}
+(id) sceneWithParam:(int)nvl;
@end
GameScene.m GameScene.m
+(id) sceneWithParam:(int)nvl
{
CCScene *scene = [CCScene node];
GameScene *layer = [GameScene node];
[scene addChild: layer];
return scene;
}
-(id) init
{
if( (self=[super init] )) {
}
return self;
}
I can't use the variable nil
inside if( (self=[super init] )) {
I have already tried to set a property test
, and to test = nvl; inside +(id) sceneWithParam:(int)nvl;
我不能在
if( (self=[super init] )) {
内使用变量nil
我已经尝试设置属性test
,并test = nvl; inside +(id) sceneWithParam:(int)nvl;
test = nvl; inside +(id) sceneWithParam:(int)nvl;
but it is not possible. 但是这是不可能的。
Yes, it's not possible to use dynamic parameters in static methods. 是的,不能在静态方法中使用动态参数。 If you want to create your object with parameters, you have to create an init method, receiving parameters you need.
如果要使用参数创建对象,则必须创建一个init方法,接收需要的参数。 Eg:
例如:
-(id) initWithYourParam:(id)param
{
if ( (self=[self init]) ) {
self.propertyParam = param;
}
return self;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.