This is a small class/function that helps you to work with animations.
So, if you want to create an animation, e.g. fading the alpha, you have to start the function like this:
CEase:start(time, type)
You should save the returned value/instance in a variable.
You can get a list of all the animation types here:https://wiki.multitheftauto.com/wiki/Easing
This are the "easing functions".
To get the returned value, which is from 0 to 1 in the most cases, I make a little example for you:
local myEase = CEase:start(1000, "InOutQuad")
function renderSth()
dxDrawRectangle(0, 0, 500, 500, tocolor(0, 0, 0, myEase.value*255))
end
addEventHandler("onClientRender", getRootElement(), renderSth)
With this small script, the alpha of the rectangle gets calculated from 0 to 255 in 1000 milliseconds.
The returned value, that you have to use for the animations, you always get like this: variable.value.
This script does not create animations, it just helps a lot at the calculating part.
Here is the class/script:
CEase = {}
CEase.__index = CEase
function CEase:start(time, typ)
local data = {}
data.start = getTickCount()
data.ending = data.start+time
data.typ = typ
data.value = 0
setmetatable(data, self)
data.easeFunc = function()
local tick = getTickCount()
local elapsed = tick-data.start
local duration = data.ending - data.start
local progress = elapsed / duration
data.value = getEasingValue(progress, data.typ)
if tick > data.ending then
removeEventHandler("onClientRender", getRootElement(), data.easeFunc)
end
end
addEventHandler("onClientRender", getRootElement(), data.easeFunc)
return data
end
I hope I've explaned everything right. I think, all should work, because I've used the same class here:
So if you want to have a lot of animations in your GUIs, this could help you a lot.