- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Structure anim_vector2i
- x.i
- y.i
- EndStructure
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Structure anim_rectangle
- A.anim_vector2i ; min
- B.anim_vector2i ; size
- EndStructure
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Enumeration
- #ANIM_LOOP
- #ANIM_PING_PONG
- EndEnumeration
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Structure animation
- animMode.l
- animSpeed.l
- animTimer.i
- animWay.l
- List region.anim_rectangle()
- EndStructure
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Structure animSprite
- atlasTexture.l
- cellWidth.l
- cellHeight.l
- Map animation.animation()
- EndStructure
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Procedure.i LoadAnimSprite(name.s, cellWidth.l, cellHeight.l, spriteMode.l = 0)
- *a.animSprite = AllocateMemory(SizeOf(animSprite))
- If *a
- InitializeStructure(*a,animSprite)
- *aatlasTexture = LoadSprite(#PB_Any,name,spriteMode)
- *acellWidth = cellWidth
- *acellHeight = cellHeight
-
- If NOT *aatlasTexture
- FreeMemory(*a)
- ProcedureReturn #Null
- EndIf
-
-
- ProcedureReturn *a
- EndIf
-
- ProcedureReturn #Null
- EndProcedure
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Procedure setAnimationFrame(*spr.animSprite, name.s, cellX.l, cellY.l)
- If *spr
- AddElement( *spranimation(name)region() )
- *spranimation(name)region()Ax = cellX * *sprcellWidth
- *spranimation(name)region()Ay = cellY * *sprcellHeight
- *spranimation(name)region()Bx = *sprcellWidth
- *spranimation(name)region()By = *sprcellHeight
- EndIf
- EndProcedure
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Procedure setAnimationSpeed(*spr.animSprite, name.s, speed.i)
- If *spr
- *spranimation(name)animSpeed = speed
- EndIf
- EndProcedure
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Procedure setAnimationMode(*spr.animSprite, name.s, mode.l)
- If *spr
- *spranimation(name)animMode = mode
- EndIf
- EndProcedure
- ; -----------------------------------------------------------------------------
- ;
- ; -----------------------------------------------------------------------------
- Procedure displayAnimationSprite(*spr.animSprite, name.s, x.f, y.f)
- If *spr
- *rect.anim_rectangle = @*spranimation(name)region()
- If *spranimation(name)animTimer < ElapsedMilliseconds()
- *spranimation(name)animTimer = ElapsedMilliseconds() + *spranimation(name)animSpeed
-
- If *spranimation(name)animMode = #ANIM_LOOP
- If NextElement(*spranimation(name)region()) = 0
- FirstElement(*spranimation(name)region())
- EndIf
- EndIf
-
- If *spranimation(name)animMode = #ANIM_PING_PONG
- Select *spranimation(name)animWay
- Case 0:
- If NextElement(*spranimation(name)region()) = 0
- *spranimation(name)animWay = 1
- EndIf
-
- Case 1:
- If PreviousElement(*spranimation(name)region()) = 0
- *spranimation(name)animWay = 0
- EndIf
-
- EndSelect
- EndIf
- EndIf
- ClipSprite(*spratlasTexture,*rectAx, *rectAy, *rectBx, *rectBy)
- DisplayTransparentSprite(*spratlasTexture,x,y)
- EndIf
- EndProcedure