Transition_EaseInBack

Syntax

Value.d = Transition_EaseInBack(t.d, b.d, c.d, d.d, backAmount.d=1.70158)

Description

Calculates an intermediate value using an "ease-in-back" transition curve. The animation starts by moving slightly backward (overshooting the start value in the negative direction) before accelerating towards the target value.

Parameters

t.d
The current elapsed time of the animation in milliseconds.

b.d
The starting value of the property being animated.

c.d
The total change in value (target value - starting value).

d.d
The total duration of the animation in milliseconds.

backAmount.d (optional)
Controls the amount of overshoot. A larger value results in a more pronounced backward movement. Default is approximately 1.70158.

Return Value

Returns the interpolated value (Double) at the current time `t` according to the ease-in-back curve.

Example

IncludeFile "ProGUI_PB.pbi"

Structure MyAnimData
  TargetValue.d
  StartValue.d
  x.d
EndStructure

Procedure DrawHandler(Window, EventType, *EventData.PG_EventDraw, *UserData.MyAnimData)
  
    DrawClear(RGB(200, 200, 200), 1) ; Grey background

    ; Draw a box whose X position is animated
    DrawBox(*UserData\x, (*EventData\height / 2) - 25, 50, 50, RGB(0, 0, 255))
    
EndProcedure

Procedure AnimateHandler(Window, EventType, *EventData.PG_EventAnimate, *UserData.MyAnimData)
  
  Select *EventData\state
  
    Case #PG_Event_Animate_Start

      Debug "Animation started."
      
    Case #PG_Event_Animate_Update

      ; Calculate intermediate value using the ease-in-back transition
      *UserData\x = Transition_EaseInBack(*EventData\currentTime, *UserData\StartValue, *UserData\TargetValue - *UserData\StartValue, *EventData\duration) 
      ; Optionally provide a custom backAmount: Transition_EaseInBack(..., ..., ..., ..., 2.5)
      
      WindowRedraw(Window)
      
    Case #PG_Event_Animate_End

      Debug "Animation ended"
      ; Ensure final value is set exactly
      *UserData\x = *UserData\TargetValue
      WindowRedraw(Window)

  EndSelect

EndProcedure

StartProGUI()

MyWindow = CreateWindow(0, 0, 300, 200, "Transition_EaseInBack Example")

If MyWindow
    
  ; Setup data for animation
  *AnimData.MyAnimData = AllocateStructure(MyAnimData)
  *AnimData\StartValue = 50 ; Start further in to see the 'back' effect clearly
  *AnimData\TargetValue = 200
    
  AddEventHandler(MyWindow, #PG_Event_Draw, @DrawHandler(), *AnimData)
  AddEventHandler(MyWindow, #PG_Event_Animate, @AnimateHandler(), *AnimData) 

  ; Start a 2-second animation
  AnimID = StartAnimation(MyWindow, #PG_Any, 2000)
  Debug "Started animation with ID: " + AnimID

  WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
  Repeat : Event = WaitWindowEvent() : Until Event = #PB_Event_CloseWindow
  
  StopAnimation(MyWindow, AnimID) ; Stop if still running
  FreeStructure(*AnimData)
  
EndIf 

StopProGUI()

See Also

Transition_EaseOutBack, Transition_EaseInOutBack, Transition_EaseOutInBack, StartAnimation

Supported OS

Windows, Linux