jcmoyer / hug

A utility library for LÖVE with a focus on simplicity
Apache License 2.0
2 stars 1 forks source link

Support animations #4

Open jcmoyer opened 10 years ago

jcmoyer commented 10 years ago

API concepts:

Animation sets can be created programmatically or described inline using a DSL.

Ideal look'n'feel:

-- create animation set programmatically
local as = aset.new()
local walk = as:addanimation('walk')
local f = walk:addframe(x,y,w,h,duration) -- duration can be in a format like '0.1s' or '100ms'
f:addattachment('lefthand',x,y)
walk:addframe(x,y,w,h,duration)
walk:addframe(x,y,w,h,duration)

as:play('walk')

function love.update(dt)
  -- animation sets need to be able to flip frames so they need to know about time passing
  as:update(dt)
end
function love.draw()
  local offsx, offsy = as:attachment('lefthand')
  love.graphics.draw(sword, objx + offsx, objy + offsy)
  love.graphics.draw(player, objx, objy, as:frame())
end

-- there should be a DSL module to make this look more descriptive
-- this module should let you load from a file:
local as = dsl.loadfile('path/to/anim/script.lua')

-- or describe it inline:
local as = dsl.run(function()
  animation 'idle' {
    frame {
      source = {x,y,w,h}, duration = '0.1s',
      attachments = {
        lefthand = {16,16}
      }
      -- alternately?: attachment 'lefthand' {16,16}
    },
    frame { ... }
  }
  animation 'walk' { ... }
end)

Things I've found a need for during LD32 and will be adding:

jcmoyer commented 9 years ago

Work has begun on the feature/animation branch.

jcmoyer commented 9 years ago

I'm going to merge everything so far (79d71d5fde970b77707013ebd2af61c6726e023e) into master then work on the rest post-LD33. Shouldn't be any breaking changes.