; **************************************************************************** ; * By PBFrance : http://www.pbfrance.com/?url=source&cmd=viewer&val=15 ; **************************************************************************** ; ----------------------------------------------------------------------------- ; ; ----------------------------------------------------------------------------- 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) *a\atlasTexture = LoadSprite(#PB_Any,name,spriteMode) *a\cellWidth = cellWidth *a\cellHeight = cellHeight If Not *a\atlasTexture FreeMemory(*a) ProcedureReturn #Null EndIf ProcedureReturn *a EndIf ProcedureReturn #Null EndProcedure ; ----------------------------------------------------------------------------- ; ; ----------------------------------------------------------------------------- Procedure setAnimationFrame(*spr.animSprite, name.s, cellX.l, cellY.l) If *spr AddElement( *spr\animation(name)\region() ) *spr\animation(name)\region()\A\x = cellX * *spr\cellWidth *spr\animation(name)\region()\A\y = cellY * *spr\cellHeight *spr\animation(name)\region()\B\x = *spr\cellWidth *spr\animation(name)\region()\B\y = *spr\cellHeight EndIf EndProcedure ; ----------------------------------------------------------------------------- ; ; ----------------------------------------------------------------------------- Procedure setAnimationSpeed(*spr.animSprite, name.s, speed.i) If *spr *spr\animation(name)\animSpeed = speed EndIf EndProcedure ; ----------------------------------------------------------------------------- ; ; ----------------------------------------------------------------------------- Procedure setAnimationMode(*spr.animSprite, name.s, mode.l) If *spr *spr\animation(name)\animMode = mode EndIf EndProcedure ; ----------------------------------------------------------------------------- ; ; ----------------------------------------------------------------------------- Procedure displayAnimationSprite(*spr.animSprite, name.s, x.f, y.f) If *spr *rect.anim_rectangle = @*spr\animation(name)\region() If *spr\animation(name)\animTimer < ElapsedMilliseconds() *spr\animation(name)\animTimer = ElapsedMilliseconds() + *spr\animation(name)\animSpeed If *spr\animation(name)\animMode = #ANIM_LOOP If NextElement(*spr\animation(name)\region()) = 0 FirstElement(*spr\animation(name)\region()) EndIf EndIf If *spr\animation(name)\animMode = #ANIM_PING_PONG Select *spr\animation(name)\animWay Case 0: If NextElement(*spr\animation(name)\region()) = 0 *spr\animation(name)\animWay = 1 EndIf Case 1: If PreviousElement(*spr\animation(name)\region()) = 0 *spr\animation(name)\animWay = 0 EndIf EndSelect EndIf EndIf ClipSprite(*spr\atlasTexture,*rect\A\x, *rect\A\y, *rect\B\x, *rect\B\y) DisplayTransparentSprite(*spr\atlasTexture,x,y) EndIf EndProcedure