HTML and CSS Reference
In-Depth Information
1. Ifthecamera x or y valueis 0 orlessthan 0 ,wefirstsetitto 0 (sothatwearenottrying
to draw from the negative space of the game map that does not exist), and we set the
corresponding colBuffer or rowBuffer to 0 .
2. If the x or y value is not 0 or greater than 0 , we next check to see whether the camera
will draw from outside the far right or far bottom of the tile map (those tiles do not
exist). If that is true, we also set the corresponding rowBuffer or colBuffer to 0 .
3. Ifoneitherthe x or y axisthecameraisinthemiddleofthetilemap,thecorresponding
colBuffer or rowBuffer issetto1.Thisaddsanextratileroworcolumntothedrawn
screen and allows the partial tile to be displayed.
Rather than simply going through this line by line, let's look at four examples and how they
would be displayed and calculated in our code.
The camera top-left position
At the upper-left position in our game world, the values to be plugged in would be those in
the list that follows. This is the simplest version of scrolling because, in effect, there is no
scrolling.
scrollRate = 4
camera.x = 0
camera.y = 0
Subtracting camera.width (160) from world.width (480) = 320. Next, we subtract
scrollRate from this result to use in calculating the value of colBuffer .
We use the same algorithm for the y axis to get rowBuffer : camera.y > (world.height - cam-
era.height) - scrollRate :
( world . width - camera . width ) - scrollRate = 316
( world . height - camera . height ) - scrollRate = 316
In this example, because the window is at the top-left corner, these values (316, 316) are not
needed, but we wanted to demonstrate them because they will be used in the examples. Be-
cause we are in the upper left corner of the map, we simply need to check for camera.x and
camera.y being less than or equal to 0 .
iif ( camera . x <= 0 ) {
camera . x = 0 ;
colBuffer = 0 ;
colBuffer = 0
iif ( camera . y <= 0 ) {
Search WWH ::




Custom Search