Objective c 具有更多背景的无限滚动

Objective c 具有更多背景的无限滚动,objective-c,cocos2d-iphone,scroll,background-image,2d-games,Objective C,Cocos2d Iphone,Scroll,Background Image,2d Games,在我的游戏中,我使用无限滚动背景。 这是我的代码: - (void)setupBackground { CGSize winSize = [CCDirector sharedDirector].winSize; // 1) Create the CCParallaxNode _backgroundNode = [CCParallaxNode node]; [self addChild:_backgroundNode z:-2]; // 2) Crea

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

- (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)];
}
它工作得很好。 但我想在游戏中改变这个背景图像与另一个,例如LV2。
我该怎么做?我试图用另一个图像创建另一个函数setupBackground2,但它不起作用。

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