0
我知道我的问题可能很愚蠢,但我搜索了,我找不到它为什么不起作用。 我创建了一个CCLayer
BackgroundLayer
类下面的实现:cocos2d在场景中添加图层
#import "BackgroundLayer.h"
@implementation BackgroundLayer
- (id)init {
if (self != nil) {
CCSprite *background = [CCSprite spriteWithFile:@"menu.png"];
background.anchorPoint = ccp(0, 0);
[self addChild:background z:-1];
NSLog(@"test");
}
return self;
}
@end
,我想它添加在主菜单中的场景,我有:
#import "MainMenuScene.h"
#import "BackgroundLayer.h"
@implementation MainMenuScene
+ (id)scene {
CCScene *scene = [CCScene node];
BackgroundLayer *backgroundLayer = [BackgroundLayer node];
[scene addChild:backgroundLayer];
return scene;
}
- (id)init {
self = [super init];
if (self != nil) {
}
return self;
}
@end
我的问题是出现NSLog
测试,但后台没有按加载。如果我在MainMenuScene
的init
方法上添加背景,它可以工作......我不应该假设该图层以这种方式工作吗?
非常感谢你! 那就是self = [] super init]。 有些时候,你是累了,初学者,你忘记了细节。 – Haris 2012-07-23 12:42:34