Game Development Reference
In-Depth Information
However, if we want to limit the scrolling so that the camera never goes backward,
all we have to do is change the code so that camera.x is only changed when
player.x is a greater value.
It's also worth noting that in a framework that supports layers, such as cocos2d,
it's possible to simplify this code by changing the position of the background layer
when it's time to scroll. This is what's employed for the sample iOS game out-
lined in Chapter 13 , Sample Game: Side-Scroller for iOS .” But for frameworks
that don't support such a feature, you'll have to implement it in a manner similar
to the preceding one.
Infinite Scrolling
Infinite scrolling is when the game continues to scroll until the player loses. Of
course, there can never be an infinite number of background segments, so at some
point the game will have to repeat images. In the case of Chapter 13 ' s infin-
ite scroller, there actually are only two nebula images, which repeat indefinitely.
However, most infinite scrollers will have a greater number of possibilities as well
as random generation thrown in to add some variety. Typically the game may have
a series of four or five background segments that must appear in order and then a
clean break after which a different series of segments can be selected.
Parallax Scrolling
In parallax scrolling , the background is broken up into multiple layers at different
depths. Each layer then scrolls at a different speed, which gives an illusion of
depth. One example could be a game where there's a cloud layer and a ground
layer. If the cloud layer scrolls more slowly than the ground layer, it gives the im-
pression that the clouds are further away than the ground.
This technique has been used in traditional animation for nearly a century, but
the first game to popularize parallax scrolling was the 1982 arcade game Moon
Patrol . On smartphone app stores, the majority of high-profile 2D games with
scrolling utilize some form of parallax scrolling, whether it's Jetpack Joyride or
Angry Birds Space . Typically only three layers are necessary to create a believable
parallax effect, as illustrated in Figure 2.7 , but more layers add more depth to the
effect.
Search WWH ::




Custom Search