Game Development Reference
In-Depth Information
How it works…
Since we have done the scrolling of background in the previous chapter, it is time we made
a separate class for it called
FSParallaxNode
. In this class, multiple backgrounds of the
same image are placed and scrolled in each update of the scene. It means that the scrolling
is done on the basis of the positions of all background nodes added to
FSParallaxNode
.
Using this
FSParallaxNode
, two objects of it are created:
BlueSkyBackground
and
WhiteMistBackground
. All are added as normal nodes to the scene in the
init
method. For them to scroll, the update method calls the
updateForDeltaTime
function
in which the class checks for the position of individual background positions reached at the
left end of the screen and changes the position so that it again starts with the right-end side.
This whole algorithm makes these individual backgrounds scroll making a full parallax
scrolling background. The parallax scrolling background really looks cool as shown in the
following screenshot: