These are some functions to help with tiled animation
Here is the source file to use:
init_tiled_animation:
type animation
range as integer
startrange as integer
currentimage as integer
delay as integer
time as integer
endtype
global dim tiledanims(0) as animation
global UsedIndices as integer
return
function load_tiled_animation( filename$ as string, imgnum as integer, width as integer, height as integer, delay as integer )
load bitmap filename$, imgnum
set current bitmap imgnum
pxwid = bitmap width( imgnum )
pxhit = bitmap height( imgnum )
pxwid = (pxwid/width)
pxhit = (pxhit/height)
index=0
if tiledanims(0).range>0
array insert at bottom tiledanims(0)
inc UsedIndices, 1
index=UsedIndices
endif
startimage = freeimage( )
tiledanims(index).startrange = startimage
tiledanims(index).range = (width*height)
tiledanims(index).delay = delay
for y=1 to height
for x=1 to width
imgindex = (startimage+((((y-1)*width)+x)-1))
if image exist( imgindex )=1 then delete image imgindex
get image imgindex, (pxwid*(x-1)), (pxhit*(y-1)), (pxwid*x)-1, (pxhit*y)-1
next x
next y
tiledanims(index).currentimage = tiledanims(index).startrange
set current bitmap 0
delete bitmap imgnum
endfunction index
function continue_tiled_animation( index )
if array count( tiledanims(0) )<index then exitfunction
if timer( )-tiledanims(index).time > tiledanims(index).delay
tiledanims(index).time = timer( )
inc tiledanims(index).currentimage
if tiledanims(index).currentimage = tiledanims(index).startrange+tiledanims(index).range
tiledanims(index).currentimage = tiledanims(index).startrange
endif
else
exitfunction
endif
endfunction
function apply_tiled_animation_to_object( obj, index )
if object exist( obj )=0 then exitfunction
texture object obj, tiledanims(index).currentimage
endfunction
function apply_tiled_animation_to_limb( obj, limb, index )
if object exist( obj )=0 then exitfunction
if limb exist( obj, limb )=0 then exitfunction
texture limb obj, limb, tiledanims(index).currentimage
endfunction
function freeimage( )
img=0
repeat
inc img
until image exist( img )=0
endfunction img
Attached is a demo project.
har har har har har
rar