My code almost works:
-- update
local anim_id = go.get(SMALL_SPRITE_URL, "animation")
local cursor = go.get(SMALL_SPRITE_URL, "cursor")
local frame_count = get_current_frame_count(anim_id)
local current_frame_number = math.ceil(cursor * frame_count)
local function get_current_frame_count(anim_id)
local atlas = go.get(SMALL_SPRITE_URL, "image")
local atlas_data = resource.get_atlas(atlas)
for k, v in ipairs(atlas_data.animations) do
if hash(v.id) == anim_id then
return v.frame_end - v.frame_start
end
end
end
It gets the correct frame number most of the time, but it’s off by maybe 1 game tick, meaning the animation frame changes, and the frame number is corrected the following frame. I don’t know how to properly debug this, but the frame number is not accurate 100% of the time.