0
我在我的cocos2d应用程序中使用视差滚动效果。我想要我的背景持续滚动;然而,我可能会错误地实现它,因为我的背景滚动到左侧,但在此之后,它再也不会回来。在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));
}
也许这有助于:http://www.learn-cocos2d.com/2012/12/ways-scrolling-cocos2d-explained/ – LearnCocos2D 2013-04-07 18:54:25