Intended for 32-bit resolutions.
Advantages to using this function instead of get image:
- It's faster than "get image"
- The loaded tilemap can be larger than the screen resolution
REM ===============================================================
REM Loads the specified image into a memblock and extracts
REM individual tiles, storing them starting with 'imgOffset'.
REM 'imgOffset' should start with 2 or higher, unless the variable
REM 'imgNoMap' at the top of the function is changed.
REM
REM Returns: Last image number used
REM ===============================================================
function loadTilemap(filename as string, imgOffset as integer, tileSize as integer)
rem these variables can be changed to fit your needs if these
rem numbers are already used elsewhere in your program
local memNoMap = 1
local memNoTile = 2
local imgNoMap = 1
local color as dword
rem load the tilemap image
load image filename, imgNoMap
rem Create the memblock to store the individual tiles
make memblock memNoTile, 12 + tileSize*tileSize*4
write memblock dword memNoTile, 0, tileSize
write memblock dword memNoTile, 4, tileSize
write memblock dword memNoTile, 8, 32
rem Create memlbock from the tilemap image
make memblock from image memNoMap, imgNoMap
imgWidth = memblock dword(memNoMap, 0)
imgHeight = memblock dword(memNoMap, 4)
rem determine how many tile rows and columns there are in the image
tileCols = imgWidth / tileSize
tileRows = imgHeight / tileSize
rem tile offset calculations
colTileOffset = tileSize*4
rowTileOffset = imgWidth*4*tileSize
rem loop through the tiles in the image
for y = 0 to tileRows-1
for x = 0 to tileCols-1
col = x*colTileOffset
row = y*rowTileOffset
rem tile offset within the image
tileOffset = row + col + 12
rem Extract pixel data from tilemap and store
rem a "tileSize by tileSize" image tile into
rem the other memblock
for iy = 0 to tileSize-1
for ix = 0 to tileSize*4-1 step 4
ty = iy*imgWidth*4
pos = tileOffset + ty + ix
rem extra pixel color from larger tilemap
color = memblock dword(memNoMap, pos)
tilePos = iy*tileSize*4 + ix + 12
rem write pixel color to smaller tile image
write memblock dword memNoTile, tilePos, color
next ix
next iy
rem create an image from tile memblock then repeat process
make image from memblock imgOffset, memNoTile
inc imgOffset, 1
next x
next y
rem free up memory
delete memblock memNoMap
delete memblock memNoTile
rem since DB can't handle expressions in the endfunction
dec imgOffset, 1
endfunction imgOffset

"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke