Cocos2d iphone 在cocos2d中创建CCParallaxNode时出现问题?

Cocos2d iphone 在cocos2d中创建CCParallaxNode时出现问题?,cocos2d-iphone,parallax,ccsprite,initializer,Cocos2d Iphone,Parallax,Ccsprite,Initializer,我在GameLayer中使用CCParallaxNode作为滚动背景,我遇到了一系列错误,我不知道为什么 “初始值设定项元素不是编译时常量”和“Unk” 您需要将代码封装在-(id)init方法中,如下所示: @implementation Background - (id)init { if (self = [super init]) { // Load the sprites for each parallax layer, from background to f

我在GameLayer中使用CCParallaxNode作为滚动背景,我遇到了一系列错误,我不知道为什么

“初始值设定项元素不是编译时常量”和“Unk”


您需要将代码封装在-(id)init方法中,如下所示:

@implementation Background

- (id)init
{
    if (self = [super init]) {
        // Load the sprites for each parallax layer, from background to foreground.
        CCSprite* para1 = [CCSprite spriteWithFile:@"color.png"];
        // ... the rest of your code ... //
    }
    return self;
}

@end

非常感谢!非常好而且简单的解释!快速提问,我得到了错误“使用未声明的标识符'ParallaxSceneTAgParallaxNode'。知道为什么吗?你需要声明那个整数。您可以使用
enum
,如下所示:
enum标记{ParallaxSceneTagParallaxNode,}
@implementation Background

- (id)init
{
    if (self = [super init]) {
        // Load the sprites for each parallax layer, from background to foreground.
        CCSprite* para1 = [CCSprite spriteWithFile:@"color.png"];
        // ... the rest of your code ... //
    }
    return self;
}

@end