Page 1 of 1
Anyone have animation code for the Sprite library?
Posted: Sat Apr 16, 2005 1:06 am
by dracflamloc
Please do not link me to ANY pb libs unless they are open source.
I just wondered if anyone had any code they'd like to share with me for playing/controlling sprite animations. No API either please =)
Posted: Sat Apr 16, 2005 10:46 am
by Num3
Me! Me! Me!
Works under linux too
Code: Select all
Structure anim
x.l
y.l
first.l
last.l
Delay.l
current.l
time.l
EndStructure
NewList Animation.anim()
Procedure Add_Animation(first,last,Delay.l);firstframe , lastframe, delay between frames
AddElement(Animation())
Animation()\x=0
Animation()\y=0
Animation()\first=first
Animation()\current=first
Animation()\last=last
Animation()\Delay=Delay
Animation()\time=ElapsedMilliseconds()
ProcedureReturn ListIndex(Animation())
EndProcedure
Procedure Animate()
ResetList(Animation())
While NextElement(Animation())
now=ElapsedMilliseconds()
If now-Animation()\time>Animation()\Delay
x=Animation()\current
Animation()\current+1
If x+1>Animation()\last
Animation()\current=Animation()\first
EndIf
Animation()\time=now
EndIf
Wend
EndProcedure
Procedure Display_Animation(number,x,y)
SelectElement(Animation(),number)
Animation()\x=x
Animation()\y=y
DisplayTransparentSprite(Animation()\current,Animation()\x,Animation()\y)
Animate()
EndProcedure
Procedure Destroy_Animation(number)
SelectElement(Animation(),number)
DeleteElement(Animation())
EndProcedure
Works like this ***pseudo code ***:
Code: Select all
loadyoursprites
Guy_Moving_Up=AddAnimation(1,6,250)
Repeat
cls
If keyhit=Move_Up
for a=1 to 10
Display_Anim(Guy_Moving_Up, x,y+a)
next
endif
flipbuffer
Forever