0
在我的遊戲中,我使用無限滾動背景。 這是我的代碼:無限滾動更多背景
- (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,但它不起作用。