我是cocos2D的新手程序员....我想使用Parallax Scrolling创建无尽的背景..我正在尝试学习视差,但它不会随着时间而更新,精灵不会继续旋转从上到下!我试过的片段如下:
-(id) init
{
if((self = [super init]))
{
CGSize wSize = [CCDirector sharedDirector].winSize;
self.isTouchEnabled = YES;
CGPoint topOffset = CGPointMake(wSize.width, 0);
CGPoint midOffset = CGPointMake(wSize.width/2,0);
CGPoint downOffset = CGPointZero;
CCSprite *para1 = [CCSprite spriteWithFile:@"Default.png"];
CCSprite *para2 = [CCSprite spriteWithFile:@"Icon.png"];
CCSprite *para3 = [CCSprite spriteWithFile:@"Default.png"];
CCSprite *para4 = [CCSprite spriteWithFile:@"Icon.png"];
paraNode = [CCParallaxNode node];
[paraNode addChild:para1 z:1 parallaxRatio:CGPointMake(0.5f, 0)
positionOffset:topOffset];
[paraNode addChild:para2 z:2 parallaxRatio:CGPointMake(1, 0) positionOffset:topOffset];
[paraNode addChild:para3 z:4 parallaxRatio:CGPointMake(2, 0) positionOffset:midOffset];
[paraNode addChild:para4 z:3 parallaxRatio:CGPointMake(3, 0) positionOffset:downOffset];
[self addChild:paraNode z:0 ];
[self scheduleUpdate];
}
return self;
}
-(void) update : (ccTime) dt
{
//Need to move the Parallax Node with the repetition of the background
}
这是实施文件......我被困在这里,用于在水平或纵向模式下移动背景的连续移动。
感谢您提前帮助
答案 0 :(得分:2)
CCParallaxNode不支持无限滚动,除非您修改其代码。我在Learn Cocos2D book中有一个无尽的视差滚动示例。从该链接,您还可以下载该书的源代码,您将在第6至8章中找到视差类。
答案 1 :(得分:0)