API Reference › Anim › Anim.play
method

Anim.play

Anim.play(entity, clip) | Anim.play(entity, fps, frames, mode)

Starts a spritesheet clip on an entity's SpriteAnim component and rewinds it to its first cell, so gameplay swaps or replays an animation with one call instead of setting five fields by hand. Two forms: Anim.play(entity, "run") plays a named clip registered with Anim.clip; Anim.play(entity, fps, frames, mode) sets the clip directly (mode 0 loop, 1 once, 2 ping-pong). A no-op if the entity has no SpriteAnim. The engine advances the clip from there each tick.

Parameters

entitythe entity carrying SpriteAnim
clipa registered clip name (2-argument form), **or**

Example

program Demo {
  property SpriteAnim { ticks: int = 0, fps: int = 0, frames: int = 0, mode: int = 0, frame: int = 0 }
  model Hero { SpriteAnim }
  entry {
    Anim.clip("run", 6, 12, 0)
    spawn Hero { SpriteAnim { } }
    let e = World.query_next(World.prop_id("SpriteAnim"), 0)
    Anim.play(e, "run")                 # by name
    Anim.play(e, 8, 4, 1)               # or directly: 4 frames @ 8fps, once
    quit()
  }
}
← All symbols