Console::Frame

console 0.2.0 · app/console/animation.rb · 239 lines · view source

Also defined here: Console::Anim

Console::Animation -- sprite animation and an animation state machine.

Two levels:

Console::Anim   a per-console registry of active animations, keyed by
                entity id. Use this for gameplay code.
Console::Frame  a single running animation (a frame counter, a finished
                flag, an interrupt lock). Use this if you need to drive
                one yourself.

Frame timing is built on DragonRuby's Numeric.frame, which is tick-based: DragonRuby ticks at 60/sec, so fps: 12 means hold_for: 5.

animate(entity, :run)                       # sprites/<kind>/<run>/*.png
animate(entity, :walk, sheet: 'hero.png',   # a sprite sheet, cropped
              frame_w: 16, frame_h: 20, frames: 6)
animate(entity, :hit, on_finish: :idle)     # one-shot, then idle
animate(entity, :die, repeat: false, lock: 12)
def initialize(spec, tick_count)
line 28
def update(tick_count)

Advance and report whether this animation has run to completion.

def finished?
line 68
def index(tick_count)
line 72
def locked?(tick_count)

Locked animations refuse to be replaced; this is how a death animation keeps a flinch from cutting it short.

def primitive_props(tick_count)

The sprite primitive properties for the current frame.

def initialize(args)
line 106
def tick_count
line 112
def update

Advance every active animation and apply finish handling.

def active?(id)
line 122
def [](id)
line 126
def name_of(id)
line 130
def playing?(id, name)
line 135
def finished?(id)
line 139
def locked?(id)
line 144
def play(entity, name, options = {})

Start an animation on an entity. Returns the Frame, or nil if the requested animation is locked out by an uninterruptible one.

def stop(id)
line 165
def stop_all
line 169
def primitive_props(entity)

The frame properties to merge into the entity's sprite primitive.

def draw(entity, spec = {})

Draw an animated sprite for an entity, using the entity's own x/y/w/h plus any transform keys it carries.

def build_spec(entity, name, options)
line 194
def animation_group(entity, name)

sprites/<kind>/<state>/... by convention, e.g. an entity with kind: :hero playing :run looks in sprites/hero/run/.