Courage.Timer#
Courage.Timer extends Petrichor.Timer with frame-based timers that tick on each fapGm_Execute frame. Use these when you care about frame count rather than wall-clock time.
Loading#
Note
Courage.Timer includes all wall-clock timers from Petrichor.Timer. You do not need to require both.
Handles#
Same as Petrichor.Timer.
Frame timer API#
Timer.after_frames(frames, fn) -> handle#
Call fn(handle) once after frames game frames.
Timer.every_frames(frames, fn) -> handle#
Call fn(handle) every frames game frames until cancelled.
Timer.after_frames_then_every(delay, interval, fn) -> handle#
Wait delay frames, call fn once, then every interval frames until cancelled.
Example#
local Timer = require("Courage.Timer")
local Log = require("Petrichor.Log")
local MyMod = mod("timer-demo")
function MyMod:init()
self._pulse = Timer.every(1.0, function()
Log.info("timer-demo", "pulse")
end)
self._frames = Timer.after_frames(60, function()
Log.info("timer-demo", "~60 frames later")
end)
end
function MyMod:shutdown()
self._pulse:cancel()
self._frames:cancel()
end
import * as Timer from "Courage.Timer"
import * as Log from "Petrichor.Log"
declare function mod(name: string): any
const MyMod = mod("timer-demo")
MyMod.init = function () {
this._pulse = Timer.every(1.0, () => {
Log.info("timer-demo", "pulse")
})
this._frames = Timer.after_frames(60, () => {
Log.info("timer-demo", "~60 frames later")
})
}
MyMod.shutdown = function () {
this._pulse.cancel()
this._frames.cancel()
}
export = MyMod