Panel:NewAnimation
table Panel:NewAnimation( number length, number delay = 0, number ease = -1, function callback = nil )
Description
Creates a new animation for the panel object.
Methods that use this function:
Arguments
3 number ease = -1
The power/index to use for easing.
- Positive values greater than 1 will ease in; the higher the number, the sharper the curve's gradient (less linear).
- A value of 1 removes all easing.
- Positive values between 0 and 1 ease out; values closer to 0 increase the curve's gradient (less linear).
- A value of 0 will break the animation and should be avoided.
- Any value less than zero will ease in/out; the value has no effect on the gradient.
4 function callback = nil
The function to be called when the animation ends. Arguments passed are:
- table animTable - The Structures/AnimationData that was used.
- Panel tgtPanel - The panel object that was animated.
Returns
1 table
Partially filled Structures/AnimationData with members:
- number EndTime - Equal to
length
anddelay
arguments added together, plus either the SysTime if there is no other animation queued or the end time of the last animation in the queue. - number StartTime - Equal to the
delay
argument, plus either the SysTime if there is no other animation queued or the end time of the last animation in the queue. - number Ease - Equal to the
ease
argument. - function OnEnd - Equal to the
callback
argument.
Example
Example on how to use this function, makes a button go around in a circle in a DFrame.
local frame = vgui.Create( "DFrame" )
frame:SetSize( 500, 500 )
frame:Center()
frame:MakePopup()
local butt = frame:Add( "DButton" )
butt:SetPos( 5, 30 )
butt:SetSize( 100, 40 )
function butt:doAnim()
local anim = self:NewAnimation( 10, 0, 1, function( anim, pnl )
self:doAnim()
end )
anim.Think = function( anim, pnl, fraction )
local radius = 200
pnl:SetPos( 250 + math.sin( Lerp( fraction, -math.pi, math.pi ) ) * radius - pnl:GetWide() / 2,
250 + math.cos( Lerp( fraction, -math.pi, math.pi ) ) * radius - pnl:GetTall() / 2 )
pnl:SetText( "Frac: " .. fraction .. "\nTime: " .. ( SysTime() - anim.StartTime ) )
end
end
butt:doAnim()