我的问题是:我需要从右到左连续移动我的精灵(方向是风景) 我搜索并找到了Ray的教程(感谢他) 但是图像似乎没有连续滚动我的代码
-(id) init
{
// always call "super" init
if( (self=[super init])) {
CGSize screenSize = [CCDirector sharedDirector].winSize;
// 1) Create the CCParallaxNode
backgroundNode = [CCParallaxNode node];
[self addChild:backgroundNode z:-1];
// 2) Create the sprites we'll add to the CCParallaxNode
Back = [CCSprite spriteWithFile:@"bg_front_spacedust.png"];
Back.rotation = -90;
Back1 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"];
Back1.rotation = -90;
// 3) Determine relative movement speeds for space dust and background
CGPoint dustSpeed = ccp(0.1, 0.1);
// 4) Add children to CCParallaxNode
[backgroundNode addChild:Back z:0 parallaxRatio:dustSpeed positionOffset:ccp(screenSize.width/2, screenSize.height/2)];
[backgroundNode addChild:Back1 z:1 parallaxRatio:dustSpeed positionOffset:ccp(screenSize.width,0)];
// 5) Enable updates
[self scheduleUpdate];
}
return self;
}
- (void)update:(ccTime)dt {
// 1) Update background position
CGPoint backgroundScrollVel = ccp(0,-1000);
backgroundNode.position = ccpAdd(backgroundNode.position, ccpMult(backgroundScrollVel, dt));
// 2) Check for background elements moving offscreen
NSArray *spaceDusts = [NSArray arrayWithObjects:Back, Back1, nil];
for (CCSprite *spaceDust in spaceDusts) {
if ([backgroundNode convertToWorldSpace:spaceDust.position].x < -spaceDust.contentSize.width) {
[backgroundNode incrementOffset:ccp(2*spaceDust.contentSize.width,0) forChild:spaceDust];
}
}
}
图像大小为1024 X 320
任何人都可以指导我这个问题
提前谢谢
答案 0 :(得分:2)
您可以在此处找到有关视差的分步指南: http://www.raywenderlich.com/3611/how-to-make-a-space-shooter-iphone-game 只需滚动一下,直到找到添加视差滚动部分。
但我建议您阅读整个教程。这真的很棒。
答案 1 :(得分:0)
试试吧..
CCSprite *bird = [CCSprite spriteWithFile:@"bird.png"];
bird.position = ccp(100,80);
[map addChild:bird];
id move = [CCMoveTo actionWithDuration:4.2 position:ccp(400, 80)];
id move1 = [CCMoveTo actionWithDuration:4.2 position:ccp(200, 80)];
[bird runAction:[CCRepeatForever actionWithAction:[CCSequence actions:move,move1, nil]]];