Cocos2D:在我稍微移动地图之前,CCParallaxNode 不会显示

发布于 2024-11-16 13:20:01 字数 1450 浏览 4 评论 0原文

我使用的是Cocos2D 0.99.5。我有一个 CCParallaxNode,其中添加了背景精灵。由于某种原因,在我开始我的地图开始移动之前,它们都不会显示。滚动随着玩家的移动而缓慢。

我已将此添加到 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)];

    }

并将此添加到更新:

    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'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];
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅紫色的梦幻 2024-11-23 13:20:01

我认为你应该在初始化内容结束时调用一次更新函数内容

[backgroundNode incrementOffset:ccp(winSize.width+(240),0) forChild:mountainNum];
[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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文