【问题标题】:How to add a background image that moves independent to main layer in Cocos and box2d如何在Cocos和box2d中添加独立移动到主层的背景图像
【发布时间】:2012-11-17 11:54:06
【问题描述】:

我想为横向滚动游戏添加背景,该游戏以与主游戏层不同的速率移动。最好的方法是什么?我可能想要 2 个背景层,每个滚动的速度都比另一个慢,以便在玩家移动时给人一种深度感。

另外,创建图层并直接控制它的最佳方法是什么?目前创建了一个图层,但我无法在代码的其他部分访问它。这是我默认使用的方式:

+(CCScene *) scene
{
// 'scene' is an autorelease object.
CCScene *scene = [CCScene node];

// 'layer' is an autorelease object.
HelloWorldLayer *layer = [HelloWorldLayer node];

// add layer as a child to scene
[scene addChild: layer];

// return the scene
return scene;
}

谢谢

【问题讨论】:

    标签: xcode background cocos2d-iphone box2d layer


    【解决方案1】:

    CCParallaxNode 对你有好处。

        // background layer: another image
        CCSprite *background = [CCSprite spriteWithFile:@"background.png"];
        background.scale = 1.5f;
        background.anchorPoint = ccp(0,0);
    
    
        // create a void node, a parent node
        CCParallaxNode *voidNode = [CCParallaxNode node];
    
        [voidNode addChild:background z:-1 parallaxRatio:ccp(0.4f,0.5f) positionOffset:CGPointZero];
    
        [voidNode addChild:tilemap z:1 parallaxRatio:ccp(2.2f,1.0f) positionOffset:ccp(0,-200)];
    
        [voidNode addChild:cocosImage z:2 parallaxRatio:ccp(3.0f,2.5f) positionOffset:ccp(200,800)];
    
    
        [self addChild:voidNode];
    

    参考 Cocos2D 示例中的 ParallaxTest。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-29
    • 2021-06-22
    • 2011-03-19
    • 2017-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    相关资源
    最近更新 更多