Game Development Reference
In-Depth Information
if (spaceBGNode.position.x <= -spaceBGNode.size.width)
{
spaceBGNode.position =
CGPointMake(spaceBGNode.position.x +
spaceBGNode.size.width*2,
spaceBGNode.position.y);
}
The next task is to update each frame to move it infinitely over the scene. Now to make it
move regularly, the moveSpaceBackground method is called in the update method of
FSMyScene in each frame.
- (void)update:(CFTimeInterval)currentTime
{
/* Called before each frame is rendered */
self.diffTime = currentTime - self.lastUpdatedTime;
self.lastUpdatedTime = currentTime;
[self moveSpaceBackground];
}
The update loop will be executed in every frame. So to move our background in every
step, we have called the moveSpaceBackground method inside the update loop.
Using this approach of infinite scrolling, we can also implement parallax gaming, which is
very common nowadays. In parallax scrolling game, there will be background and player
in separate layers and they will be moving at the same time at different speeds. This will
give the user a perception of some real-time movement of the player against the back-
ground.
Search WWH ::




Custom Search