Skip to content

Courage.Anim#

require("Courage.Anim") plays skeletal animations (.bck files) on game actors. Animations are loaded asynchronously from archive files and stepped each frame before rendering.

Loading the module#

local Anim = require("Courage.Anim")
import * as Anim from "Courage.Anim"

API#

Function Returns Description
Anim.play(actor, arc, resIdx, opts?) id or nil Play animation resource index resIdx from archive arc on actor (native pointer). Returns an animation handle id on success, nil on failure.
Anim.stop(id) (none) Stop and detach the animation layer id.
Anim.stop_all(actor) (none) Stop all animation layers associated with actor (native pointer).
Anim.is_ready(id) boolean Returns true once the animation archive resource has finished loading.
Anim.is_done(id) boolean Returns true if a non-looping animation has reached its final frame. Returns true if id is invalid.
Anim.frame(id) number Returns the current animation frame index. Returns 0.0 if not ready or invalid.
Anim.set_frame(id, frame) boolean Set the current animation playback frame. Returns true on success.
Anim.set_rate(id, rate) boolean Set the playback speed multiplier. Returns true on success.

Options table#

The fourth argument to Anim.play is an optional table with these fields:

Field Type Default Description
loop boolean true Loop animation playback.
rate number 1.0 Playback speed multiplier.
start number 0.0 Starting frame index.
joints integer[] nil Array of joint indices to restrict the animation to (partial joint animation). If omitted or empty, applies to all joints.

Example#

local Hook = require("Augment.Hook")
local Anim = require("Courage.Anim")

local s_animId = nil

Hook["daAlink_c::execute"]:before(function(ctx)
    if s_animId ~= nil then
        if Anim.is_done(s_animId) then
            Anim.stop(s_animId)
            s_animId = nil
        end
        return
    end

    local link = ctx.self
    s_animId = Anim.play(link, "custom_anm", 0, {
        loop = false,
        rate = 1.0,
        start = 0.0,
    })
end)
import * as Hook from "Augment.Hook"
import * as Anim from "Courage.Anim"

let animId: number | undefined

Hook.daAlink_c_execute.before((ctx) => {
    if (animId !== undefined) {
        if (Anim.is_done(animId)) {
            Anim.stop(animId)
            animId = undefined
        }
        return
    }

    const link = ctx.self
    animId = Anim.play(link, "custom_anm", 0, {
        loop: false,
        rate: 1.0,
        start: 0.0,
    })
})

See also#