Skip to content

luxe API (2025.1.2)


luxe: system/anim.modifier module


Anim

import "luxe: system/anim.modifier" for Anim

Anim is an animation player attached to an entity.

It plays animations from animation assets or ones created from code. Animations can target the entity Anim is attached to, but can target any entity. For example, a level cutscene could be played back from one entity, but it drives several other entities. From assets like scenes and prototypes, Anim provides an autoplay list, for playing when loaded.

You can play multiple animations at the same time, for example, the player might have a walk animation playing and you play a glowing animation on top.

Anim supports curve, linear and discrete driven animations and is expanded on by World Systems that provide animation tracks.

  • create(entity: Entity)
  • destroy(entity: Entity)
  • has(entity: Entity)
  • valid(entity: Entity, anim: Anim)
  • get_source_id(entity: Entity, anim: Anim)
  • get_state(entity: Entity, anim: Anim)
  • get_active_anims(entity: Entity)
  • play(entity: Entity, anim_lx: ID, time_offset: Num)
  • blend(entity: Entity, anim_lx: ID, blend_time: Num, time_offset: Num)
  • play(entity: Entity, anim_lx: ID)
  • blend(entity: Entity, anim_lx: ID, blend_time: Num)
  • play_only(entity: Entity, anim_lx: ID, time_offset: Num)
  • play_only(entity: Entity, anim_lx: ID)
  • stop(entity: Entity, anim: Anim, reset: Bool)
  • stop(entity: Entity, anim: Anim)
  • stop_all(entity: Entity, reset: Bool)
  • stop_all(entity: Entity)
  • create_track(entity: Entity, anim: Anim, track_id: Any, track_type: Any)
  • has_track(entity: Entity, anim: Anim, track_id: Any)
  • track_set_range(entity: Entity, anim: Anim, track_id: Any, min: Any, max: Any)
  • track_get_range(entity: Entity, anim: Anim, track_id: Any)
  • track_set(entity: Entity, anim: Anim, track_id: Any, property: Any, value: Any)
  • track_set_channel(entity: Entity, anim: Anim, track_id: Any, channel_id: Any, channel_idx: Any, interp: Any, keys: Any)
  • set_play_count(entity: Entity, anim: Anim, play_count: Num)
  • set_rate(entity: Entity, anim: Anim, rate: Num)
  • set_start(entity: Entity, anim: Anim, start: Num)
  • set_end(entity: Entity, anim: Anim, end: Num)
  • set_interval_time(entity: Entity, anim: Anim, time: Num)
  • get_play_count(entity: Entity, anim: Anim)
  • get_rate(entity: Entity, anim: Anim)
  • get_duration(entity: Entity, anim: Anim)
  • get_start(entity: Entity, anim: Anim)
  • get_end(entity: Entity, anim: Anim)
  • get_interval_time(entity: Entity, anim: Anim)
  • on_event(entity: Entity, anim: Anim, fn: Fn)

Anim.create(entity: Entity) returns unknown

Attach an Anim modifier to entity.

var entity = Entity.create(world)
Anim.create(entity)

Anim.destroy(entity: Entity) returns None

Detach and destroy the Anim attached to entity.

Anim.destroy(entity)

Anim.has(entity: Entity) returns Bool

Returns whether entity has an Anim modifier attached.

if(Anim.has(entity)) {
  Log.print("found anim")
}

Anim.valid(entity: Entity, anim: Anim) returns Bool

Returns whether the Anim instance is valid for the Anim attached to entity.

var anim = Anim.play(entity, "player/idle")
if(!Anim.valid(entity, anim)) {
  Log.print("oh no!")
}

Anim.get_source_id(entity: Entity, anim: Anim) returns ID

Returns the ID of the animation asset that the Anim instance was played from, if known, by asking the Anim attached to entity. Returns null if not.

var anim = Anim.play(entity, "player/idle")
var source_id = Anim.get_source_id(entity, anim)
Log.print(Strings.get(source_id)) //expect: "player/idle"

Anim.get_state(entity: Entity, anim: Anim) returns AnimState

Return the animation state of the Anim instance, by asking the Anim attached to entity.

var anim = Anim.play(entity, "player/idle")
var state = Anim.get_state(entity, anim)
if(state == AnimState.playing) {
  Anim.stop(entity, anim)
}

Anim.get_active_anims(entity: Entity) returns List

Returns a list of Anim instances that are active on the Anim attached to entity.

var active = Anim.get_active_anims(entity)
for(anim in active) {
  var state = Anim.get_state(entity, anim)
  Log.print(AnimState.name(state));
}

Anim.play(entity: Entity, anim_lx: ID, time_offset: Num) returns Anim

Play the animation asset anim_lx on the Anim attached to entity. The time_offset is a time in seconds to begin playback from. For example, you might pause an animation and hold onto the animation time when it was paused. Then when resuming, you can play from the new time. Returns the newly started Anim instance.

var anim = Anim.play(entity, "player/idle", 0.5)

Anim.blend(entity: Entity, anim_lx: ID, blend_time: Num, time_offset: Num) returns Anim

Play the animation asset anim_lx on the Anim attached to entity with a blend fade time. The time_offset is a time in seconds to begin playback from. The blend_time is handled by some tracks, not all. Returns the newly started Anim instance.

//fade in the animation over 0.6 seconds
var anim = Anim.blend(entity, "player/idle", 0.6)

Anim.play(entity: Entity, anim_lx: ID) returns Anim

Play the animation asset anim_lx on the Anim attached to entity. Plays from the beginning. Returns the newly started Anim instance.

var anim = Anim.play(entity, "player/idle")

Anim.blend(entity: Entity, anim_lx: ID, blend_time: Num) returns Anim

Play the animation asset anim_lx on the Anim attached to entity with a blend fade time. Plays from the beginning. Blend time is handled by some tracks, not all. Returns the newly started Anim instance.

//fade in the animation over 0.6 seconds
var anim = Anim.blend(entity, "player/idle", 0.6)

Anim.play_only(entity: Entity, anim_lx: ID, time_offset: Num) returns Anim

Play the animation asset anim_lx on the Anim attached to entity, stopping all other active anims, and only playing this one. The time_offset is a time in seconds to begin playback from. Returns the newly started Anim instance.

var anim = Anim.play_only(entity, "player/idle", 0.5)

Anim.play_only(entity: Entity, anim_lx: ID) returns Anim

Play the animation asset anim_lx on the Anim attached to entity, stopping all other active anims, and only playing this one. Returns the newly started Anim instance.

var anim = Anim.play_only(entity, "player/idle")

Anim.stop(entity: Entity, anim: Anim, reset: Bool) returns None

Stop the Anim instance if playing on the Anim attached to entity.

If reset is true, the state of anything that was being animated by this Anim instance, will be reset to what it was before it was played. For example, if your animation is changing the transform position, it will revert back to the position at the time the animation was played.

var anim = Anim.play(entity, "player/idle")
Anim.stop(entity, anim, true)

Anim.stop(entity: Entity, anim: Anim) returns None

Stop the Anim instance if playing on the Anim attached to entity. State is not reset (see Anim.stop(entity, anim, reset)).

var anim = Anim.play(entity, "player/idle")
Anim.stop(entity, anim)

Anim.stop_all(entity: Entity, reset: Bool) returns None

Stop all active Anim instances playing on the Anim attached to entity. If reset is true, state will be reset to the state before the animation started (see Anim.stop(entity, anim, reset)).

var anim = Anim.play(entity, "player/idle")
Anim.stop_all(entity, true)

Anim.stop_all(entity: Entity) returns None

Stop all active Anim instances playing on the Anim attached to entity. State is not reset (see Anim.stop(entity, anim, reset)).

var anim = Anim.play(entity, "player/idle")
Anim.stop_all(entity)

Anim.create_track(entity: Entity, anim: Anim, track_id: Any, track_type: Any) returns unknown

no docs found

Anim.has_track(entity: Entity, anim: Anim, track_id: Any) returns unknown

no docs found

Anim.track_set_range(entity: Entity, anim: Anim, track_id: Any, min: Any, max: Any) returns unknown

no docs found

Anim.track_get_range(entity: Entity, anim: Anim, track_id: Any) returns unknown

no docs found

Anim.track_set(entity: Entity, anim: Anim, track_id: Any, property: Any, value: Any) returns unknown

no docs found

Anim.track_set_channel(entity: Entity, anim: Anim, track_id: Any, channel_id: Any, channel_idx: Any, interp: Any, keys: Any) returns unknown

no docs found

Anim.set_play_count(entity: Entity, anim: Anim, play_count: Num) returns None

Set the amount of times to play the Anim instance on the Anim attached to entity. The play_count value can be 0, which will loop forever.

//play 3 times and then end
var anim = Anim.play(entity, "player/idle")
Anim.set_play_count(entity, anim, 3)

Anim.set_rate(entity: Entity, anim: Anim, rate: Num) returns None

Set the playback rate of the Anim instance on the Anim attached to entity. The rate of 1 is the default speed. 0.5 is half speed, and 2 is twice as fast.

var anim = Anim.play(entity, "player/idle")
Anim.set_rate(entity, anim, 0.5)

Anim.set_start(entity: Entity, anim: Anim, start: Num) returns None

Set the start marker of the Anim instance on the Anim attached to entity. note This API is WIP.

Anim.set_start(entity, anim, 0)

Anim.set_end(entity: Entity, anim: Anim, end: Num) returns None

Set the end marker of the Anim instance on the Anim attached to entity. note This API is WIP.

Anim.set_end(entity, anim, 1)

Anim.set_interval_time(entity: Entity, anim: Anim, time: Num) returns None

Set the current playback time of the Anim instance on the Anim attached to entity. note This API is WIP.

Anim.set_interval_time(entity, anim, 0.5)

Anim.get_play_count(entity: Entity, anim: Anim) returns Num

Return the play count of the Anim instance on the Anim attached to entity.

var play_count = Anim.get_play_count(entity, anim)

Anim.get_rate(entity: Entity, anim: Anim) returns Num

Return the rate of playback of the Anim instance on the Anim attached to entity.

var play_count = Anim.get_play_count(entity, anim)

Anim.get_duration(entity: Entity, anim: Anim) returns Num

Return the duration of the Anim instance on the Anim attached to entity.

var play_count = Anim.get_play_count(entity, anim)

Anim.get_start(entity: Entity, anim: Anim) returns Num

Return the start marker of the Anim instance on the Anim attached to entity.

var play_count = Anim.get_play_count(entity, anim)

Anim.get_end(entity: Entity, anim: Anim) returns Num

Return the end marker of the Anim instance on the Anim attached to entity.

var play_count = Anim.get_play_count(entity, anim)

Anim.get_interval_time(entity: Entity, anim: Anim) returns Num

Return the current playback time of the Anim instance on the Anim attached to entity. note This API is WIP.

var play_count = Anim.get_play_count(entity, anim)

Anim.on_event(entity: Entity, anim: Anim, fn: Fn) returns None

no docs found

AnimEvent

import "luxe: system/anim.modifier" for AnimEvent

no docs found


AnimEvent.start returns unknown

An event fired when an animation started playing.

AnimEvent.tick returns unknown

An event fired when an animation is updated, but only if the track is set to emit the event.

AnimEvent.complete returns unknown

An event fired when an animation is stopped or done playing.

AnimInterpolation

import "luxe: system/anim.modifier" for AnimInterpolation

An enum for types of interpolation in animation tracks.


AnimInterpolation.unknown returns unknown

An invalid or unknown value.

if(value == AnimInterpolation.unknown) {
  Log.print("unknown interpolation type!")
}

AnimInterpolation.curve returns unknown

The animation values between keys will be interpolated according to the curve defined by the keys themselves.

if(value == AnimInterpolation.curve) {
  Log.print("curve")
}

AnimInterpolation.linear returns unknown

The animation values between keys will be interpolated linearly. For example if your keys were { time=0 value=0 } and { time=1 value=4 }, at the time of 0.5 the value would be 2, half of the next key.

if(value == AnimInterpolation.linear) {
  Log.print("linear")
}

AnimInterpolation.discrete returns unknown

The animation values between keys would not be interpolated, they would jump from one value to the next. For example if your keys were { time=0 value=0 } and { time=1 value=3 }, with discrete the value at time 0.5 is still 0 (instead of 1.5 with linear). It will only change to 3 when the next key is reached.

if(value == AnimInterpolation.discrete) {
  Log.print("discrete")
}

AnimInterpolation.name(value: AnimInterpolation) returns String

Convert an AnimInterpolation value to a string.

var type = AnimInterpolation.linear
var name = AnimInterpolation.name(type)
Log.print("type is %(name)") //expect: "linear"

AnimInterpolation.from_string(value: String) returns AnimInterpolation

Get the AnimInterpolation value to a name.

var type = AnimInterpolation.from_string("discrete")
Log.print("discrete is value %(type)") //expect: "3", the internal value

AnimInterval

import "luxe: system/anim.modifier" for AnimInterval

no docs found


AnimInterval.create(world: Any, duration: Any, rate: Any) returns unknown

no docs found

AnimInterval.create(world: Any, duration: Any) returns unknown

no docs found

AnimInterval.time(world: Any, anim: Any) returns unknown

no docs found

AnimInterval.set_time(world: Any, anim: Any, time: Any) returns unknown

no docs found

AnimInterval.set_now(world: Any, anim: Any, offset: Any) returns unknown

no docs found

AnimInterval.set_now(world: Any, anim: Any) returns unknown

no docs found

AnimInterval.set_play_count(world: Any, anim: Any, count: Any) returns unknown

no docs found

AnimInterval.set_clock(world: Any, anim: Any, clock: Any) returns unknown

no docs found

AnimInterval.set_rate(world: Any, anim: Any, rate: Any) returns unknown

no docs found

AnimInterval.set_duration(world: Any, anim: Any, duration: Any) returns unknown

no docs found

AnimInterval.set_start(world: Any, anim: Any, start: Any) returns unknown

no docs found

AnimInterval.set_end(world: Any, anim: Any, end: Any) returns unknown

no docs found

AnimInterval.get_now(world: Any, anim: Any) returns unknown

no docs found

AnimInterval.get_play_count(world: Any, anim: Any) returns unknown

no docs found

AnimInterval.get_clock(world: Any, anim: Any) returns unknown

no docs found

AnimInterval.get_rate(world: Any, anim: Any) returns unknown

no docs found

AnimInterval.get_duration(world: Any, anim: Any) returns unknown

no docs found

AnimInterval.get_start(world: Any, anim: Any) returns unknown

no docs found

AnimInterval.get_end(world: Any, anim: Any) returns unknown

no docs found

AnimState

import "luxe: system/anim.modifier" for AnimState

An enum for the state of an Anim instance.


AnimState.inactive returns Num

The animation is inactive. :todo: This may be obsolete.

var state = Anim.get_state(entity, anim)
if(state == AnimState.inactive) {
  Log.print("anim is inactive")
}

AnimState.playing returns Num

The animation is active and is playing.

var state = Anim.get_state(entity, anim)
if(state == AnimState.playing) {
  Log.print("anim is playing")
}

AnimState.ending returns Num

The animation is ending, and will be marked complete next update.

var state = Anim.get_state(entity, anim)
if(state == AnimState.ending) {
  Log.print("anim is ending")
}

AnimState.complete returns Num

The animation has ended and is complete.

var state = Anim.get_state(entity, anim)
if(state == AnimState.complete) {
  Log.print("anim is complete")
}

AnimState.name(value: Num) returns String

Convert an AnimState value to a string.

var type = AnimState.ending
var name = AnimState.name(type)
Log.print("type is %(name)") //expect: "ending"

AnimState.from_string(value: String) returns Num

Convert a string to an enum value.

var state = AnimState.from_string("ending")
var same = state == AnimState.ending //true

Data

import "luxe: system/anim.modifier" for Data

no docs found

  • var play : List = []

System

import "luxe: system/anim.modifier" for System

no docs found

  • new(world: World)

System.new(world: World) returns System

no docs found