I'm trying to get the number of frames in an animation. It's stored as the frame_count property of the animation prototype but I believe there's no way to get the prototype of a LuaRenderObject.
There's neither a LuaRenderObject.prototype field nor a table in the prototypes object that contains the animation prototypes.
Let me know if I'm mistaken, but if not, can you please add an interface in the API
Thanks!
LuaRenderObject.prototype or prototypes.animation
Re: LuaRenderObject.prototype or prototypes.animation
What do you want to use the frame_count for?
I'm an admin over at https://wiki.factorio.com. Feel free to contact me if there's anything wrong (or right) with it.
Re: LuaRenderObject.prototype or prototypes.animation
https://lua-api.factorio.com/latest/cla ... #animation
The exact same property name as on creation.
Or if you mean that animation prototypes are missing from runtime entirely, you should rephrase your request to ask for that.
The exact same property name as on creation.
Or if you mean that animation prototypes are missing from runtime entirely, you should rephrase your request to ask for that.
Re: LuaRenderObject.prototype or prototypes.animation
I posted another interface request for pausing/restarting animations. In that thread I talked about a script work around. That solution requires the frame count such that you can calculate the frame the animation should be at.
The code is still work in progress, but here's what I currently have to give you an idea:
Code: Select all
local AnimationWrapper = {}
AnimationWrapper.__index = AnimationWrapper
function AnimationWrapper.new(lua_render_object, frame_count)
local self = setmetatable({}, AnimationWrapper)
self.animation = lua_render_object
self.base_speed = 1
self.paused_frame = nil
self.last_start_tick = game.tick
self.frame_count = frame_count
self.animation.animation_speed = self.base_speed
self.animation.animation_offset = (game.tick * self.base_speed) % self.frame_count
return self
end
-- Pause the animation.
-- Capture the current displayed frame and stop the animation.
function AnimationWrapper:pause()
local current_tick = game.tick
local current_frame = (self.animation.animation_offset + current_tick * self.base_speed) % self.frame_count
self.paused_frame = current_frame
self.animation.animation_speed = 0
self.animation.animation_offset = current_frame
end
function AnimationWrapper:start()
local current_tick = game.tick
self.animation.animation_speed = self.base_speed
if self.paused_frame then
self.animation.animation_offset = (self.paused_frame - current_tick * self.base_speed) % self.frame_count
else
self.animation.animation_offset = (current_tick * self.base_speed) % self.frame_count
end
self.last_start_tick = current_tick
self.paused_frame = nil
end
function AnimationWrapper:set_speed(new_speed)
local current_tick = game.tick
if self.animation.animation_speed ~= 0 then
local current_frame = (self.animation.animation_offset + current_tick * self.base_speed) % self.frame_count
self.base_speed = new_speed
self.animation.animation_speed = new_speed
self.animation.animation_offset = (current_frame - current_tick * new_speed) % self.frame_count
self.last_start_tick = current_tick
else
self.base_speed = new_speed
self.animation.animation_speed = 0
end
end
return AnimationWrapper
Last edited by jurgy on Sun Mar 09, 2025 1:11 pm, edited 1 time in total.
Re: LuaRenderObject.prototype or prototypes.animation
Yeah, the animation prototype is afaik missing entirely from the runtime. As to why I need the prototype; I need the frame_count of an animation which is stored in it.curiosity wrote: Sun Mar 09, 2025 12:49 pm https://lua-api.factorio.com/latest/cla ... #animation
The exact same property name as on creation.
Or if you mean that animation prototypes are missing from runtime entirely, you should rephrase your request to ask for that.