开发者

Cocos2D: CCParallaxNode doesn't display until I move my map a bit

I'm using Cocos2D 0.99.5. I have a CCParallaxNode with background sprites added to it. For some reason, none of them display until I start my map starts moving around a bit. The scroll slowly with the players movement.

I have this added to init:

    winSize = [CCDirector sharedDirector].winSize;

    bgMountainsMax = floor(winSize.width/240)+1;

    if((int)winSize.width%240 > 0){
        bgMountainsBumper = ((int)winSize.width%240)/bgMountainsMax;
    }else{
        bgMountainsBumper = 0;
    }

    backgroundNode = [CCParallaxNode node];
    [self addChild:backgroundNode z:-1];

    CGPoint mountainSpeed = ccp(0.5, 0.5);

    bgMountains = [[NSMutableArray alloc] initWithCapacity: bgMountainsMax];

    for(int i=0; i<bgMountainsMax; ++i){
        mountain = [CCSprite spriteWithFile:@"mountainBG1.png"];
        mountain.opacity = 80;
        [bgMountains insertObject:mountain atIndex:i];

        [backgroundNode addChild:[bgMountains objectAtIndex:i] z:0 parallaxRatio:mountainSpeed positionOffset:ccp((240*i)+(bgMountainsBumper*i),98)];

    }

And this added to update:

    for (CCSprite *mountainNum in bgMountains) {
    if ([backgroundNode convertToWorldSpace:mountainNum.position].x < -开发者_高级运维(240/2)) {
        [backgroundNode incrementOffset:ccp(winSize.width+(240),0) forChild:mountainNum];
    }

    if ([backgroundNode convertToWorldSpace:mountainNum.position].x > winSize.width+(240/2)) {          
        [backgroundNode incrementOffset:ccp(-(winSize.width+240),0) forChild:mountainNum];
    }
}


I think you should be calling the update function stuff once at the end of your init stuff

[backgroundNode incrementOffset:ccp(winSize.width+(240),0) forChild:mountainNum];
[backgroundNode incrementOffset:ccp(-(winSize.width+240),0) forChild:mountainNum];

without the conditionals, to set it up initially.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜