0

通常我采取行动 layer.m 并在其 init 方法中添加对视差方法的调用,例如:

    [self addScrollingBackgroundWithParallax];

该方法是:

-(void)addScrollingBackgroundWithParallax {
CGSize screenSize = [[CCDirector sharedDirector] winSize];
CGSize levelSize = [[GameManager sharedGameManager]
                    getDimensionsOfCurrentScene];

// 1. Create image (sprite node)
CCSprite *BGLayer1 = [CCSprite spriteWithFile:@"chap9_scrolling4.png"];

// 2. Create Parallax Node, Position it 
parallaxNode = [CCParallaxNode node];
[parallaxNode setPosition:ccp(levelSize.width/2.0f,screenSize.height/2.0f)];
float xOffset = 0;
// 3. Add image node to parallax node
[parallaxNode addChild:BGLayer1 z:1 parallaxRatio:ccp(1.0f,1.0f) positionOffset:ccp(0.0f,0.0f)];
xOffset = (levelSize.width/2) * 0.3f;
// 4. Add parallax node to layer
[self addChild:parallaxNode z:1];

}

这工作正常。所以我试图做一些不同的事情。在游戏场景类中,我初始化以下内容:

-(id)init{
self = [super init];
if (self != nil) {
    // The scene will start out by running layer1
    _layer = [PlaneLevel node];
    [self addChild:_layer z:1];

    //Add eye candy
    layer2 = [Scene2EyeCandy node];
    [self addScrollingBackgroundWithParallax];

}
return self;

}

一个gamelayer和一个eyecandy层。我将游戏层添加到场景中,但是我没有将 eyecandy 层添加到场景中,而是调用了 addScrollingBackgroundWithParallax 方法来执行此操作:

-(void)addScrollingBackgroundWithParallax {
CGSize screenSize = [[CCDirector sharedDirector] winSize];
CGSize levelSize = [[GameManager sharedGameManager] getDimensionsOfCurrentScene];
// 1. Creates the parallax node
CCParallaxNode *parallaxNode = [CCParallaxNode node];
// 2. Positions it
[parallaxNode setPosition:ccp(levelSize.width/2.0f,screenSize.height/2.0f)];

float xOffset = 0;
// 3. Adds the eyecandy layer to the parallax node 
[parallaxNode addChild:layer2 z:40 parallaxRatio:ccp(1.0f,1.0f) positionOffset:ccp(0.0f,0.0f)];

xOffset = (levelSize.width/2) * 0.3f;
// 4. Finally add the parallax node to the scene.
[self addChild:parallaxNode z:1];

}

但是当我运行游戏时,我根本没有得到眼睛糖果层。

4

1 回答 1

0

当然,你不知道。你的代码:

//Add eye candy
layer2 = [Scene2EyeCandy node];
[self addScrollingBackgroundWithParallax];

那么在哪里

[self addChild: layer2];

?

于 2012-12-19T06:01:44.340 回答