cocos2d アプリで視差スクロール効果を使用しています。背景を継続的にスクロールしたい; ただし、背景が左にスクロールするため、正しく実装していない可能性がありますが、その後は二度と戻ってきません。
コードは次のとおりです。
- (void) setUpBackground
{
CGSize winSize = [CCDirector sharedDirector].winSize;
// Create the CCParallaxNode
_backgroundNode = [CCParallaxNode node];
[self addChild:_backgroundNode z:-2];
// Create ths prites
para1 = [CCSprite spriteWithFile:@"bg.png"];
para2= [CCSprite spriteWithFile:@"shipp.png"];
// Determine relative movement speeds for trees and background
CGPoint treeSpeed = ccp(0.1, 0.1);
CGPoint bgSpeed = ccp(0.5, 0.5);
// Add children to the CCParallexNode
[_backgroundNode addChild:para1 z:0
parallaxRatio:treeSpeed
positionOffset:ccp(160,winSize.height/2)];
[_backgroundNode addChild:para2 z:1
parallaxRatio:bgSpeed
positionOffset:ccp(para1.contentSize.width* para1.scale, winSize.height/2)];
}
- (void)updateBackground:(ccTime)dt
{
CGPoint backgroundScrollVel = ccp(-1000, 0);
_backgroundNode.position = ccpAdd(_backgroundNode.position, ccpMult(backgroundScrollVel, dt));
}