Game Development Reference
In-Depth Information
Figure 2.8 Scene broken up into four segments to support four-way scrolling.
Because we can also scroll vertically, we need to update the y-position of the cam-
era, as well:
Click here to view code image
camera.y = clamp(player.y, screenHeight / 2,
vCount * screenHeight -
screenHeight / 2)
Calculating the new location of the background sprite based on the camera also
must take into account the y-position:
Click here to view code image
draw s at ( s.x - camera.x + screenWidth /2,
s.y - camera.y - screenHeight / 2)
Todeterminewhichbackgroundsegmentsneedtobedrawn,wecan'tusethesame
approach as in horizontal scrolling. That's because there isn't just a single list of
background sprites to iterate through. A basic approach might be to use a two-di-
mensional array to store the segments and determine both the row and column of
the top-left segment on the screen. Once that segment is computed, it is trivial to
get the other three visible segments.
Search WWH ::




Custom Search