Panel/NewAnimation

From Garry's Mod
Jump to: navigation, search
 Panel:NewAnimation( )

Contents

Description

Creates a new animation for the panel object.

Methods that use this function:

Arguments

number length

The length of the animation in seconds.

Arguments

number delay=0

The delay before the animation starts.

Arguments

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.

Arguments

function callback=nil

The function to be called when the animation ends. Arguments passed are:

Returns

table

Partially filled AnimationData structure with members:

  • number EndTime - Equal to length and delay 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.

Examples

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()


Personal tools
Navigation