Game Development Reference
In-Depth Information
{
NSString* frameName = [NSString stringWithFormat:@"bg%i.png", i];
CCSprite* sprite = [CCSprite spriteWithSpriteFrameName:frameName];
sprite.anchorPoint = CGPointMake(0, 0.5f);
sprite.position = CGPointMake(0, screenSize.height / 2);
[spriteBatch addChild:sprite z:i tag:i];
}
// 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.anchorPoint = CGPointMake(0, 0.5f);
sprite.position = CGPointMake(screenSize.width, 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];
}
The stripes' anchorPoint is changed from its default (0.5f, 0.5f) to (0,
0.5f) to make them left-aligned. Doing that makes it easier to work with the parallax
sprites, because in this particular case you don't want to have to take into account that
that texture's origin and the sprite's x position aren't at the same location. Figure 7-6
shows how this makes it easier to calculate the x position.
 
Search Nedrilad ::




Custom Search