Basically, i got this 512x512 image that has 1024 16x16 squares on it.
Now what i want to do, is specify a size (1x1 = 16x16 pixels, some textures will be 32x32 instead of 16x16 so these have a size of 2x2 squares). And a number, where the first line is 0-15, second line is 16-31 etc. and i already got this code:
global image = 8
id = FREE_IMAGE()
load image "terrain.png",id
make memblock from image 1,id
function FREE_IMAGE()
repeat
inc image
until image exist(image) = 0
endfunction image
function LOAD_TEXTURE(num,xsize,ysize)
id = FREE_IMAGE()
make memblock 2,16*16*4+12
write memblock dword 2,0,xsize*16
write memblock dword 2,4,ysize*16
write memblock dword 2,8,32
for x = 1 to 16
for y = 1 to 16
rem Here it should read from the big image
writelocation = ((y-1)*16 + x - 1)*4 + 12
write memblock dword 2,writelocation,rgb(rnd(255),rnd(255),rnd(255))
next y
next x
make image from memblock id,2
delete memblock 2
endfunction id
And then a texture would be created like:
dirt = LOAD_TEXTURE(0,1,1)
^ would load the first image, top left, in the file, dirt is the id of the image holding the texture
I've attached the terrain.png with 2 tiles filled in.
...