Here are two ways to use tiles.
1: Save each tile as a different file and load them individualy.
Pros - Loading time is quicker.
Con - Takes up way more disk space than it should.
2: Save all tiles into one image and cut them up during run-time.
Pros - Use smaller disk space.
Con - Slower loading time.
If you use no.2 (I use no.2) you may have notice that when you attempt to load all your
tiles at one time, there will be a noticable lag or pause. I didn't like that so I got it to
only load a single tile I needed at one time.
The following code is a sample of what I personaly use for a Tileset of 10x?? tiles. Meaning 10 tiles
across and as many downwards as you want.
remstart
Lazy Tile Loader
remend
set display mode 640,480,16
sync on
sync rate 0
`DBC dont have global variables, but Arrays are global and can substitute.
dim TileSize(0)
dim TileSetTerrain(0)
dim PtrTerrain(0)
dim Bitmap32x32(0)
TileSize(0) = 32
TileSetTerrain(0) = 20
PtrTerrain(0) = 2000
Bitmap32x32(0) = 1
`Load the TileSet.
load image "terrain.png",TileSetTerrain(0),1
create bitmap Bitmap32x32(0),32,32
set current bitmap 0
do
cls
DrawTerrain(1,32,32)
DrawTerrain(2,64,64)
DrawTerrain(3,96,96)
sync
loop
Function DrawTerrain(t,x,y)
Tile = PtrTerrain(0)+t
`Checks if the image is loaded
if image exist(Tile)
`If Image is loaded already just paste it.
paste image Tile,x,y,1
else
`If Image is not then extract it and pasted to the screen.
b = current bitmap()
set current bitmap Bitmap32x32(0)
x = (t-t/10*10)*TileSize(0)*-1
y = (t/10)*TileSize(0)*-1
Paste image TileSetTerrain(0),x,y
get image Tile,0,0,TileSize(0),TileSize(0),1
set current bitmap b
paste image Tile,x,y,1
endif
EndFunction
My tileset is attached. Dont mind all the black empty spaces, it's just currently undecided and I plan to fill it in maybe.