Game Development Reference
In-Depth Information
Then it's filled with factors in the init method of the ParallaxBackground
class. Notice how NSNumber numberWithFloat is used to store a float value in-
side the array. I explain the code that adds additional background sprites in the next
section. I added the following code just above the scheduleUpdate line in the
init method:
Listing 7-3. Modified init methodof the ParallaxBackground class
numStripes = 7;
// Add 7 more stripes, flip them and position them next to their neighbor stripe
for (int i = 0; i < numStripes; i++)
NSString* frameName = [NSString stringWithFormat:@"bg%i.png", i];
CCSprite* sprite = [CCSprite spriteWithSpriteFrameName:frameName];
// Position the new sprite one screen width to the right
sprite.position = CGPointMake(screenSize.width + screenSize.width / 2, ←
screenSize.height / 2);
// Flip the sprite so that it aligns perfectly with its neighbor
sprite.flipX = YES;
// Add the sprite using the same tag offset by numStripes
[spriteBatch addChild:sprite z:i tag:i + numStripes];
// Initialize the array that contains the scroll factors for individual stripes.
speedFactors = [NSMutableArray arrayWithCapacity:numStripes];
[speedFactors addObject:[NSNumber numberWithFloat:0.3f]];
[speedFactors addObject:[NSNumber numberWithFloat:0.5f]];
[speedFactors addObject:[NSNumber numberWithFloat:0.5f]];
[speedFactors addObject:[NSNumber numberWithFloat:0.8f]];
[speedFactors addObject:[NSNumber numberWithFloat:0.8f]];
Search Nedrilad ::

Custom Search