I'm new to LÖVE.
I want to interpolate between two frames in a sprite animation. The code below is extremly slow when called in love.draw().
What is the best/most efficient way to implement sprite interpolation?
Thank you!
Code: Select all
function InterpolateImage(firstImage, secondImage, tweenFactor)
local width = firstImage:getData():getWidth()
local height = firstImage:getData():getHeight()
imageData = love.image.newImageData(width, height)
for x = 0, image:getWidth() - 1 do
for y = 0, image:getHeight() - 1 do
r1, g1, b1, a1 = firstImage:getData():getPixel(x,y)
r2, g2, b2, a2 = secondImage:getData():getPixel(x,y)
-- interolate
imageData:setPixel(x, y,
r1 + (r2 - r1) * tweenFactor,
r1 + (r2 - r1) * tweenFactor,
r1 + (r2 - r1) * tweenFactor,
r1 + (r2 - r1) * tweenFactor)
end
end
return love.graphics.newImage(imageData)
end