so i stumbled over your new LuaRendering API and was really happy about it's seemingly endless possibilities.
But i soon ran into an issue when i changed the animation speeds of the turbine blades and shadow to simulate wind speeds.
For the orientation i replaced the animations by simply using rendering.set_animation() which didn't cause frame skips but i thought i should maybe mention it.
It would be really nice if the animation wouldn't skip frames when you changed it's speed.
I thought it was possible to calculate the frame offset, but it doesn't seem to be deterministic at all... (but i'm sure my formula is correct .. at least now) (it also glitches when i dont replace the animation)
Code: Select all
game.print("total ticks "..(game.tick-turbine.creation_tick))
local current_wind_speed = wind_speeds[turbine.base.surface.name]*WIND_SPEED_MULT
turbine.last_frame_count = turbine.last_frame_count+(game.tick-turbine.last_change)*turbine.last_speed
game.print("actual frames until now: "..turbine.last_frame_count)
game.print("changing speed to "..current_wind_speed)
local new_frame_number = (game.tick-turbine.creation_tick) * current_wind_speed
game.print("expected frame at new speed: "..new_frame_number)
local new_offset = (new_frame_number-turbine.last_frame_count)*-1
game.print("calculated offset: "..new_offset)
rendering.set_animation_speed(turbine.turbine,current_wind_speed )
rendering.set_animation_speed(turbine.shadow,current_wind_speed)
rendering.set_animation_offset(turbine.shadow,new_offset)
rendering.set_animation_offset(turbine.turbine,new_offset)
turbine.last_change = game.tick
turbine.last_speed = current_wind_speed
Happy new year!