These functions will create milli second delay based animation with images from number to number(ex: 20-30 which means all the 10 images from 20 to 30 will be ran in the animation)
The animation is a sprite that his image will be updated to perform an animation.
Several animation sprites can run at the same time and are seperated using their ID numbers.
Here is an example to show how to use the system with the system itself. (some commands are not used but are self explained)
Rem Project: Animation System
Rem Created: 3/19/2007 6:05:53 PM
Rem ***** Main Source File *****
rem init
sync on : sync rate 0
rem animation system type
type t_anim
id as integer
spr as integer
x as integer
y as integer
prio as integer
imgStart as integer
imgEnd as integer
delay as integer
time as integer
playing as boolean
frame as integer
maxFrames as integer
endtype
create bitmap 1,40,40 : set current bitmap 1
for i=1 to 4
circle 25,25,i+10
get image i,0,0,40,40,1
cls
next i
delete bitmap 1 : set current bitmap 0
rem initialize animation system
animInit()
for i=1 to 20
rem add animation
animId=animFree()
animAdd(animId,freeSprite(),rnd(400),rnd(400),1,1,4,rnd(400)+100)
rem play the animation
animPlay(animId)
next i
rem main loop
do
rem clean screen
cls
rem update animations
animUpdate()
rem update screen
fastsync
rem end of main loop
loop
function freeSprite()
repeat
inc i,1
until sprite exist(i)=0
endfunction i
`********************
`* Animation System *
`********************
function animInit()
global dim anim(0) as t_anim
endfunction
function animAdd(id as integer,spr as integer,x as integer,y as integer,prio as integer,imgStart as integer,imgEnd as integer,delay as integer)
if animGetIndex(id)=0
array insert at bottom anim(0)
ind=array count(anim(0))
anim(ind).id=id
anim(ind).spr=spr
anim(ind).x=x
anim(ind).y=y
anim(ind).prio=prio
anim(ind).imgStart=imgStart
anim(ind).imgEnd=imgEnd
anim(ind).delay=delay
anim(ind).time=0
anim(ind).playing=0
anim(ind).frame=1
anim(ind).maxFrames=anim(ind).imgEnd-anim(ind).imgStart
sprite anim(ind).spr,0,0,anim(ind).imgStart
set sprite priority anim(ind).spr,anim(ind).prio
set sprite anim(ind).spr,0,1
else
exit prompt "ID with the same number was added.","Animation Debugger"
endif
endfunction
function animPlay(id as integer)
anim(animGetIndex(id)).playing=1
endfunction
function animStop(id as integer)
anim(animGetIndex(id)).playing=0
endfunction
function animSetFrame(id as integer,frame as integer)
anim(animGetIndex(id)).frame=frame
endfunction
function animDelete(id as integer)
delete sprite anim(animGetIndex(id)).spr
array delete element anim(0),animGetIndex(id)
endfunction
function animGetIndex(id as integer)
for i=1 to array count(anim(0))
if anim(i).id=id
result=i
exit
else
result=0
endif
next i
endfunction result
function animFree()
repeat
inc i,1
until animGetIndex(i)=0
endfunction i
function animSetPos(id as integer,x as integer,y as integer)
anim(animGetIndex(id)).x=x
anim(animGetIndex(id)).y=y
endfunction
function animGetPosX(id as integer)
result=anim(animGetIndex(id)).x
endfunction result
function animGetPosY(id as integer)
result=anim(animGetIndex(id)).y
endfunction result
function animReset(id as integer)
anim(animGetIndex(id)).frame=1
endfunction
function animUpdate()
for i=1 to array count(anim(0))
if anim(i).playing
if anim(i).time=0 then anim(i).time=timer()
if timer()=>anim(i).time+anim(i).delay
if anim(i).frame=anim(i).maxFrames
anim(i).frame=1
else
anim(i).frame=anim(i).frame+1
endif
anim(i).time=timer()
endif
sprite anim(i).spr,anim(i).x,anim(i).y,anim(i).frame+(anim(i).imgStart-1)
endif
next i
endfunction