diff --git a/init.lua b/init.lua index b6fa992..043c2b9 100644 --- a/init.lua +++ b/init.lua @@ -1187,18 +1187,23 @@ function M.load_textures(rig, asset_aliases) -- Bind each bone to its uv-rect; resolve anchor (uv.w/2, uv.h/2 default). -- Anchor is a rig-author concern: bone-level b.anchor (set in rig table) -- takes precedence; tile UV center is the fallback. - for _, b in ipairs(rig.bones) do - if b.texture then - local tile = by_name[b.texture] + -- + -- The render loop reads from bones_by_id (via bones_z_sorted), not from + -- rig.bones (which keeps the original rig_table.bones reference). We + -- must write atlas_uv onto the bones_by_id objects so render sees it. + for _, b_src in ipairs(rig.bones) do + if b_src.texture then + local tile = by_name[b_src.texture] if tile == nil then error("puppet.load_textures: atlas '" .. rig.asset_pack - .. "' has no tile '" .. b.texture .. "'") + .. "' has no tile '" .. b_src.texture .. "'") end - b.atlas_uv = tile.uv + local target = rig.bones_by_id[b_src.id] + target.atlas_uv = tile.uv -- sprite_reach for locomotion: tile height minus anchor.y - b.texture_height = tile.uv.h - if b.anchor == nil then - b.anchor = { tile.uv.w / 2, tile.uv.h / 2 } + target.texture_height = tile.uv.h + if target.anchor == nil then + target.anchor = { tile.uv.w / 2, tile.uv.h / 2 } end end end