【问题标题】:cocos2d add layers on scenecocos2d 在场景中添加图层
【发布时间】:2012-07-23 08:02:13
【问题描述】:

我知道我的问题可能很愚蠢,但我进行了搜索,但找不到它不起作用的原因。 我创建了一个CCLayerBackgroundLayer,实现如下:

#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 测试,但没有加载背景。如果我在MainMenuSceneinit 方法上添加背景,它可以工作......我不应该认为图层是这样工作的吗?

【问题讨论】:

    标签: cocos2d-iphone add layer


    【解决方案1】:

    不确定是否相关,但您在 BackgroundLayer 中忘记了 self = [super init];

    尝试注释掉锚点线,看看图像是否显示出来。

    【讨论】:

    • 非常感谢!!!那是 self=[]super init]。有时你累了,初学者忘记了细节。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多