Get previous currentValue of animator to compare

Windows

I have an image that I follows an animator on the path of a polygon

I would like to flip the image on the X-axis depending on which way it's going.

My idea for a solution is comparing the current X value of the animator to the previous currentValue() of the animator. Is that possible? I'm not sure how to get the previous currentValue. Im considering trying to save it using datastore but that seems excessive.

Thanks in advance for any help

I think I have a solution.

I called playdate.graphics.animator:currentValue() at the beginning of playdate.update() and later on and there was a change in values so I can take the difference.

You can do something like this:

local prevValue
function playdate.update()
local diff = currentValue() - prevValue

-- rest of your code...

prevValue = currentValue()
end

At the beginning of your update, prevValue will have the value from the previous frame (except for the very first call to update, so maybe you can to set that to something by default)

1 Like