2

我的问题是:我需要从右到左位置连续移动我的精灵(方向是横向)我已经搜索并找到了 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
任何人都可以在这个问题上指导我
提前谢谢

4

2 回答 2

2

您可以在此处找到有关视差的分步指南: http ://www.raywenderlich.com/3611/how-to-make-a-space-shooter-iphone-game 只需滚动一点,直到找到添加视差滚动部分。

但我建议阅读整个教程。它真的很好。

于 2013-08-19T07:55:56.340 回答
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]]];
于 2016-04-15T08:04:35.870 回答