Pixel by Pixel Scrolling - General Concept

First of all, you should take a glance at some one else's code, like that RPG demo in Rel Lib.

A map is just a bi-dimensional array of tiles. If you want an huge level which scrolls 25 screens, and you have, say, 16x16 tiles, you'll need (320/16)=20; 20 * 25 = 500 tiles width, and let's say that 12 tiles heigh.

I usually define a TYPE to hold map data. I don't have more than 240 tiles, so I only need a byte to store tile references. I also need other byte for status to store if a tile is solid, or it is a platform... It saves memory if I use a BYTE for each:

TYPE mapData
tile AS STRING*1
status AS STRING*1
' Now I define my map
DIM map(500,12) AS mapData

Performing tile by tile scrolling and pixel by pixel scrolling is *the same* if you are using a library, but a little bit more difficult in pure QB without pure QB libs (which are libs too, against many "pureist" thoughts :) ), 'cause pure QB BCOM45.LIB doesn't support clipping, and you need it for P*P scrolling. To do it, you have to define a "camera" position. This camera can follow the player, or be sticked to it... The camera position will determine which portion of the map will be visible.

Por a p&p scrolling the camera has to be mesured in pixels (or even in smaller measures: I use pixel/100 to get smooth movement), and you need a simple SUB like this to draw your map data, passing just the camera position:

SUB drawMap(xC%, Map() AS mapData, Tiles%())
xTile%=xC%/16 ' Tile position
xOffset%=xC% AND 15 ' like xC% MOD 16
' but faster !!
' Now we draw 21 tiles, the first
' in a negative position (outside
' the screen). That's why we need
' an outside library (pureQB or not
' pureQB).
FOR x%=0 TO 20
FOR y%=0 TO 12
drawTile 16*(x%+xTile%)-xOffset%,16*y%,t%,tiles%() ' [*]
'[*] We suppose the drawTile as a defined SUB
' which draws a tile and takes these
' parameters:
' drawTile xPos%, yPos%, index%, tileArray%()
' And draws tile # index% from tileArray%
' at position (xPos%, yPos%)

This code is not tested (I've written it here directly), but it may work :D

Happy coding. 8==) na_th_an

PixelByPixelScrollingGeneral - page last edited 2005-11-23 07:22:28 by (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster