无限滚动与更多背景



在我的游戏中,我使用了无限滚动背景。这是我的代码:

- (void)setupBackground {
    CGSize winSize = [CCDirector sharedDirector].winSize;
    // 1) Create the CCParallaxNode
    _backgroundNode = [CCParallaxNode node];
    [self addChild:_backgroundNode z:-2];
    // 2) Create the sprites you’ll add to the
    // CCParallaxNode
    _spacedust1 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"];
    _spacedust2 = [CCSprite spriteWithFile:@"bg_front_spacedust.png"];
    _planetsunrise = [CCSprite spriteWithFile:@"bg_planetsunrise.png"];
    _galaxy = [CCSprite spriteWithFile:@"bg_galaxy.png"];
    _spacialanomaly = [CCSprite spriteWithFile:@"bg_spacialanomaly.png"];
    _spacialanomaly2 = [CCSprite spriteWithFile:@"bg_spacialanomaly2.png"];
    // 3) Determine relative movement speeds for space dust
    // and background
    CGPoint dustSpeed = ccp(0.1, 0.1);
    CGPoint bgSpeed = ccp(0.05, 0.05);
    // 4) Add children to CCParallaxNode
    [_backgroundNode addChild:_spacedust1 z:0
                parallaxRatio:dustSpeed
               positionOffset:ccp(0,winSize.height/2)];
    [_backgroundNode addChild:_spacedust2 z:0
                parallaxRatio:dustSpeed
               positionOffset:ccp(_spacedust1.contentSize.width*
                                  _spacedust1.scale, winSize.height/2)];
    [_backgroundNode addChild:_galaxy z:-1
                parallaxRatio:bgSpeed
               positionOffset:ccp(0,winSize.height * 0.7)];
    [_backgroundNode addChild:_planetsunrise z:-1
                parallaxRatio:bgSpeed
               positionOffset:ccp(600,winSize.height * 0)];
    [_backgroundNode addChild:_spacialanomaly z:-1
                parallaxRatio:bgSpeed
               positionOffset:ccp(900,winSize.height * 0.3)];
    [_backgroundNode addChild:_spacialanomaly2 z:-1
                parallaxRatio:bgSpeed
               positionOffset:ccp(1500,winSize.height * 0.9)];
}

效果很好。但是我想在游戏过程中把这个背景图像换成另一个,比如LV 2。我该怎么做呢?我试图用另一个图像创建另一个函数setupBackground2,但它不起作用。

在从CCTextureCache addmage:方法加载/获取纹理后,使用setTexture:改变现有精灵的纹理

最新更新