일반적으로 나는 나의 행동 layer.m을 가지고 init 메소드에 같은 시차 메소드에 호출을 추가 :시차 층 GameScene에 표시되지
[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 층. 나는 현장에 gamelayer를 추가하지만 대신 현장에 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];
}
을하지만 게임을 실행할 때 내가 얻을 해달라고 eyecandy 레이어.
노드가 표시되지 않는 경우의 체크리스트 : http://www.learn-cocos2d.com/2012/09/reasons-node-show/ – LearnCocos2D