From 7859709ac3b1500e3037c5dceacb77bcff778e89 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Mon, 30 Mar 2026 17:50:02 -0400 Subject: Read frame durations from aseprite files --- src/sprite.lua | 5 +++-- src/textures.lua | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sprite.lua b/src/sprite.lua index b790a9e..0048b9f 100644 --- a/src/sprite.lua +++ b/src/sprite.lua @@ -47,11 +47,12 @@ end) function sprite_anim_sys(ent, dt) local sprite = ent.sprite local tag = sprite.anim.tags[sprite.active_tag] + local frame_duration = sprite.anim.frame_durations[sprite.frame] sprite.timer = sprite.timer + dt - if sprite.timer > tag.duration then + if sprite.timer > frame_duration then sprite.frame = sprite.frame + 1 - sprite.timer = 0 + sprite.timer = sprite.timer - frame_duration end if sprite.frame >= tag.to then diff --git a/src/textures.lua b/src/textures.lua index 9ed789c..05a00a3 100644 --- a/src/textures.lua +++ b/src/textures.lua @@ -5,8 +5,9 @@ local default_anim = { frame_count = 1, default_tag = "default", tags = { - default = {from=1, to=1, duration=1}, + default = {from=1, to=1}, }, + frame_durations = {0.1} } local img_bank = {} @@ -20,6 +21,7 @@ local function load_ase(path) local height = ase.header.height local frames = {} + local durations = {} local tags = {} local default_tag @@ -30,6 +32,7 @@ local function load_ase(path) local buf = love.data.decompress("data", "zlib", cel.data) local data = love.image.newImageData(cel.width, cel.height, "rgba8", buf) local img = lg.newImage(data) + table.insert(durations, frame.frame_duration / 1000) table.insert(frames, {img=img, x=cel.x, y=cel.y}) elseif chunk.type == 0x2018 then for i, tag in ipairs(chunk.data.tags) do @@ -41,7 +44,6 @@ local function load_ase(path) from = tag.from + 1, to = tag.to + 1, -- this is placed wrong but idc - duration = (tag.frame_duration or 100) / 1000, } end end @@ -60,6 +62,7 @@ local function load_ase(path) frame_count = #frames, default_tag = default_tag, tags = tags, + frame_durations = durations, } end -- cgit v1.3-2-g0d8e