Game Development Reference
In-Depth Information
How to do it...
Now is the time for action; perform the following steps to add the infinite scrolling back-
ground to your game.
1. Import the SpaceBackground.png file provided in the Resources folder.
2. Add a function in FSMyScene for initializing the infinite background.
3. In order to enable scrolling, we have to add two identical background sprite nodes
one after the other.
4. In the function, run a for loop for two background nodes specifying the position,
a name (tag), and then adding to SKMyScene .
5. Hence, the initalizingScrollingBackground function looks like this:
- (void)initalizingScrollingBackground
{
for (int index = 0; index < 2; index++)
{
SKSpriteNode *spaceBGNode =
[SKSpriteNode
spriteNodeWithImageNamed:@"SpaceBackground.png"];
{
spaceBGNode.position =
CGPointMake(index *
spaceBGNode.size.width, 0);
spaceBGNode.anchorPoint = CGPointZero;
spaceBGNode.name = @"SpaceBG";
[self addChild:spaceBGNode];
}
}
}
6. Add this method into the init method and also move the code to add a spaceship
into a different method called addSpaceship .
Search WWH ::




Custom Search