我一直试图让一个图层进入我的场景。我的场景叫做“生存”。我的图层叫做“SSpriteLayer”。场景初始化,但图层没有。
SURVIVAL.H:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "SSpriteLayer.h"
@interface Survival : CCLayer {}
@end
SURVIVAL.M:
@implementation Survival
+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];
// 'layer' is an autorelease object.
Survival *layer = [Survival node];
SSpriteLayer *spriteLayer = [SSpriteLayer node];
// add layer as a child to scene
[scene addChild: layer];
[scene addChild: spriteLayer];
// return the scene
return scene;
}
-(id) init
{
if( (self=[super init]))
NSLog(@"SCENE HAS INIT");
return self;
}
@end
SSPRITELAYER.H:
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface SSpriteLayer : CCLayer {
}
@end
SSPRITELAYER.M:
#import "SSpriteLayer.h"
@implementation SSpriteLayer
-(id) init
{
if( (self=[super init]))
NSLog(@"SPRITELAYER HAS INIT");
return self;
}
@end
我不明白为什么我的图层没有初始化,为什么我没有在调试区域收到“SPRITELAYER HAS INIT”消息。
答案 0 :(得分:0)
// add layer as a child to scene
[self addChild: layer];
[self addChild: SpriteLayer];
更改并尝试
答案 1 :(得分:0)
确保您致电
[Survival scene];
不
[Survival node];
并在此处调用您的场景发布代码