Code : Tout sélectionner
Enumeration Window
#mainForm
EndEnumeration
Enumeration Gadget
#image
EndEnumeration
Global Image = CreateImage(#PB_Any, 100, 100, 24)
Declare Start()
Declare ChangeFrame()
Declare Exit()
Start()
Procedure Start()
;Creation de trois frames
StartDrawing(ImageOutput(Image))
Box(0, 0, 100, 100, RGB(255, 0, 0)) ;Red
StopDrawing()
AddImageFrame(Image)
StartDrawing(ImageOutput(Image))
Box(0, 0, 100, 100, RGB(0, 0, 255)) ;Blue
StopDrawing()
AddImageFrame(Image)
StartDrawing(ImageOutput(Image))
Box(0, 0, 100, 100, RGB(255, 215, 0)) ;Yellow
StopDrawing()
;Affichage du nombre de frames : On a bien les 3 frames
Debug "Image frame count " + ImageFrameCount(Image)
;Selection de la première frame
SetImageFrame(Image, 0)
OpenWindow(#mainForm, 0, 0, 500, 300, "Image animée", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ImageGadget(#image, 10, 10, 0, 0, ImageID(Image))
AddWindowTimer(#mainForm, 0, 1000)
;Triggers
BindEvent(#PB_Event_CloseWindow, @Exit())
BindEvent(#PB_Event_Timer, @ChangeFrame())
Repeat : WaitWindowEvent() : ForEver
EndProcedure
Procedure ChangeFrame()
Static Frame
Frame +1
If Frame = 3
Frame = 0
EndIf
SetImageFrame(Image, Frame)
SetGadgetState(#Image, ImageID(Image))
EndProcedure
Procedure Exit()
End
EndProcedure