-
What do you want to achieve?
I’m trying to render an animation to an EditableImage, with a certain delay after every frame that can vary from frame to frame. -
What is the issue?
The animation will sometimes render too slowly (likely due to the time it takes to render to the EditableImage taking time in itself). You see, I’mtask.wait()
ing for that set delay after every time I draw, but it doesn’t account for that EditableImage draw time. -
What solutions have you tried so far?
I tried tracking the time before I render the frame and the time after rendering the frame and getting the difference, then subtracting that from the time Itask.wait()
. Unfortunately, this still doesn’t work, going too slowly for some animations. To test, Itask.wait()
ed for a very short time like 0.00001 seconds and the animation rendered at a speed almost true to the original, so I know it is possible for the animation to render fast. A completely different thing I’ve tried is making a separate EditableImage for each frame and then switching them under the Decal, but for some reason that doesn’t draw many of the pixels as it animates.
Here’s my current solution that goes too slow for some animations with short delays:
local editableImage = (editable image)
local pixels = {}
local numFrames = (number of frames)
local frameIndex = 1
while true do
local delay = howLongDelayIsForThisFrameInSecondsFunction(frameIndex)
local start = os.clock() -- track beginning time?
-- both of the below functions probably take a decent amount of time
putPixelsOntoPixelsArray(frameIndex, pixels)
editableImage:WritePixels(Vector2.zero, editableImage.Size, pixels)
local difference = os.clock() - start -- should get the time lost when doing the above operations
frameIndex = frameIndex % numFrames + 1
task.wait(delay - difference) -- theoretically, subtracting the above lost time should compensate for it, but it doesn't.
-- Fast playing animations (as in, with short delays) are still rendered/drawn slow.
-- Remember, I know it's possible for them to play at the right speed, but I need a way to do delay after each frame that will work for all animations
end