Reputation: 2277
In my I've defined a CCLayer like this:
@interface MyLayer : CCLayer {
CCLayer * referenceLayer;
}
How should I declare it to use it in +(CCScene *) scene ?
Like this ?
@property (nonatomic, retain) CCLayer *referenceLayer;
Upvotes: 0
Views: 113
Reputation: 69027
Since + (id)scene
is a class method, you cannot access an ivar/property from within it. One possible solution is having a static variable in your layer.m file, like in the following snippet:
static CCScene* _scene = nil;
+ (id)scene {
if (_scene == nil) {
_scene = [[CCScene node] retain];
//-- further scene initializaion
}
return _scene;
}
This simple approach has a drawback: you can only have one such layer around.
Upvotes: 1