Skip to content

Kaplay.Timer

Modules

Comp

Values

addTimerComponent

addTimer(context, maxLoopsPerFrame: float=?) => Types.comp Enable timer related functions like wait(), loop(), tween() on the game object.

let addTimer: (
Kaplay.Context.t,
~maxLoopsPerFrame: float=?,
) => Kaplay.Types.comp
Parameters
option < float >
Return type
getMaxLoopsPerFrame

The maximum number of loops per frame allowed, to keep loops with sub-frame intervals from freezing the game.

let getMaxLoopsPerFrame: T.t => float
Parameters
T.t
Return type
float
loop

Run the callback every n seconds. If waitFirst is false (the default), the function will be called once on the very next frame, and then loop like normal.

let loop: (
T.t,
float,
unit => unit,
~maxLoops: int=?,
~waitFirst: bool=?,
) => unit
Parameters
T.t
float
unit
unit
option < int >
option < bool >
Return type
unit
loopWithController

Run the callback every n seconds. If waitFirst is false (the default), the function will be called once on the very next frame, and then loop like normal.

let loopWithController: (
T.t,
float,
unit => unit,
~maxLoops: int=?,
~waitFirst: bool=?,
) => Kaplay.TimerController.t
Parameters
T.t
float
unit
unit
option < int >
option < bool >
setMaxLoopsPerFrame

The maximum number of loops per frame allowed, to keep loops with sub-frame intervals from freezing the game.

let setMaxLoopsPerFrame: (T.t, float) => unit
Parameters
T.t
float
Return type
unit
tween

tween(context, from, to, duration in seconds, setValue, easeFunc=?) => unit

Useful to change a property of a Game Object over time.

k
->Context.tween(
  ~from=-15.,
  ~to_=0.,
  ~duration=0.5,
  ~setValue=Bird.setAngle(bird, ...),
)
let tween: (
T.t,
~from: 'v,
~to_: 'v,
~duration: float,
~setValue: 'v => unit,
~easeFunc: Kaplay.Types.easeFunc=?,
) => unit
Parameters
T.t
float
unit
Return type
unit
tweenWithController

tween(context, from, to, duration in seconds, setValue, easeFunc=?) => TweenController.t

Useful to change a property of a Game Object over time.

k
->Context.tween(
  ~from=-15.,
  ~to_=0.,
  ~duration=0.5,
  ~setValue=Bird.setAngle(bird, ...),
)
let tweenWithController: (
T.t,
~from: 'v,
~to_: 'v,
~duration: float,
~setValue: 'v => unit,
~easeFunc: Kaplay.Types.easeFunc=?,
) => Kaplay.TweenController.t
Parameters
T.t
float
unit
wait

wait(t, duration in seconds, action?) Run the callback after n seconds.

let wait: (T.t, float, ~action: unit => unit) => unit
Parameters
T.t
float
unit
unit
Return type
unit
waitWithController

wait(t, duration in seconds, action?) Run the callback after n seconds.

let waitWithController: (
T.t,
float,
~action: unit => unit,
) => Kaplay.TimerController.t
Parameters
T.t
float
unit
unit