StopAnimation

Syntax

Success = StopAnimation(Object, ID)

Description

Stops a specific animation loop that was previously started on a ProGUI object (Window or Widget) using StartAnimation().

Parameters

Object
The handle of the ProGUI Window or Widget on which the animation is running.

ID
The integer identifier of the animation to stop. This must match the ID provided to or returned by the corresponding StartAnimation() call.

Return Value

Returns #True if the animation was found and successfully stopped (or queued to be stopped). Returns #False if the `Object` handle is invalid or no animation with the specified `ID` was found running on that object.

Remarks

Stopping an animation prevents further #PG_Event_Animate_Update events from being dispatched for that animation ID. Depending on the internal implementation, it might trigger a final #PG_Event_Animate_End event immediately or simply cease updates. It's generally good practice to ensure the animated property reaches its final intended state when stopping an animation manually, if required.

Example

IncludeFile "ProGUI_PB.pbi"

Global MyAnimationID

Procedure AnimateHandler(Object, EventType, *EventData.PG_EventAnimate, *UserData)
  Static Counter
  Select *EventData\state
    Case #PG_Event_Animate_Start
      Debug "Animation started (will run indefinitely)"
      Counter = 0
    Case #PG_Event_Animate_Update
      Counter + 1
      Debug "Animation Update #" + Str(Counter)
      ; Stop the animation after 50 updates
      If Counter >= 50
        Debug "Stopping animation..."
        StopAnimation(Object, *EventData\id)
      EndIf
    Case #PG_Event_Animate_End
      Debug "Animation explicitly stopped or completed"
  EndSelect
EndProcedure

StartProGUI()
MyWindow = CreateWindow(0, 0, 300, 200, "StopAnimation Example")

If MyWindow
  AddEventHandler(MyWindow, #PG_Event_Animate, @AnimateHandler())
  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  ; Start an indefinite animation (Duration=0)
  MyAnimationID = StartAnimation(MyWindow) 

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf 

StopProGUI()

See Also

StartAnimation, AnimationGetCurrentTime, #PG_Event_Animate

Supported OS

Windows, Linux