Game Development Reference
In-Depth Information
a sprite frame cache loads in the sprite sheet and allows other classes to grab the
correct sprites.
ScrollingLayer
ScrollingLayer is a generic class I created that allows for two or more
screen-sized segments to scroll infinitely. To construct a ScrollingLayer ,
you pass in an array that lists out all of the background sprite names, as well
as the speed (pixels/second) at which the layer should scroll. To simplify things,
ScrollingLayer assumes that there is enough memory to load in all of the
backgrounds at the same time.
The update function is where most of the work happens in this file. What it does
is shift the positions of all the background sprites by however many pixels have
been traversed on a particular frame. Once a background sprite fully scrolls off the
screen, it has its position moved to be all the way to the right of any other back-
ground sprites. This way, when it's time for a particular image to appear onscreen
again, it will slide in properly.
When I originally implemented the nebula scrolling layer, there was an issue with
a seam (a one pixel vertical line) visible when the nebula wrapped back to the be-
ginning (see Figure 13.2 ) . After poring over the code I became frustrated because
I did not see any issue with the implementation of ScrollingLayer . However,
one of my technical reviewers pointed out that the issue was actually in the nebula
image files I was using. It turned out that one of the files had a vertical line of
gray pixels that was causing the issue. Once the grey pixels were eliminated from
the image file, the nebula scrolled perfectly. Let this be a lesson that you should
always double-check your content and make sure it's not causing any issues!
Search WWH ::




Custom Search