Panel/AlphaTo

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m
Line 1: Line 1:
 
{{Func
 
{{Func
|Name=AlphaTo
 
|Parent=Panel
 
 
|Description=Uses animation to transition the current alpha value of a panel to a new alpha, over a set period of time and after a specified delay.
 
|Description=Uses animation to transition the current alpha value of a panel to a new alpha, over a set period of time and after a specified delay.
 
|Realm=Client
 
|Realm=Client
Line 28: Line 26:
 
* {{FuncArg|table|animData|The {{Struct|AnimationData}} that was used.}}
 
* {{FuncArg|table|animData|The {{Struct|AnimationData}} that was used.}}
 
* {{FuncArg|Panel|pnl|The panel object whose alpha was changed.}}
 
* {{FuncArg|Panel|pnl|The panel object whose alpha was changed.}}
 +
}}
 +
{{Example
 +
|Description=Make the derma frame fading out in 1 second.
 +
|Code=local DermaPanel = vgui.Create( "DFrame" )
 +
DermaPanel:SetPos( 100, 100 )
 +
DermaPanel:SetSize( 300, 110 )
 +
DermaPanel:SetTitle( "My derma frame" )
 +
DermaPanel:SetDraggable( true )
 +
DermaPanel:MakePopup()
 +
 +
local DermaButton = vgui.Create( "DButton", DermaPanel )
 +
DermaButton:SetText( "Fade out" )
 +
DermaButton:SetPos( 25, 40 )
 +
DermaButton:SetSize( 250, 50 )
 +
DermaButton.DoClick = function()
 +
DermaPanel:AlphaTo( 0, 1, 0, function()
 +
DermaPanel:Remove() -- Remove the DFrame when the animation is over
 +
end )
 +
end
 +
|Output=[[Image:AlphaTo_Fade_Out.gif‎]]
 
}}
 
}}

Revision as of 20:07, 16 January 2020

 Panel:AlphaTo( )

Contents

Description

Uses animation to transition the current alpha value of a panel to a new alpha, over a set period of time and after a specified delay.

Arguments

number alpha

The alpha value (0-255) to approach.

Arguments

number duration

The time in seconds it should take to reach the alpha.

Arguments

number delay=0

The delay before the animation starts.

Arguments

function callback

The function to be called once the animation finishes. Arguments are:

Examples

Example

Make the derma frame fading out in 1 second.

local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 100, 100 )
DermaPanel:SetSize( 300, 110 )
DermaPanel:SetTitle( "My derma frame" )
DermaPanel:SetDraggable( true )
DermaPanel:MakePopup()

local DermaButton = vgui.Create( "DButton", DermaPanel )
DermaButton:SetText( "Fade out" )
DermaButton:SetPos( 25, 40 )
DermaButton:SetSize( 250, 50 )
DermaButton.DoClick = function()
	DermaPanel:AlphaTo( 0, 1, 0, function() 	
		DermaPanel:Remove() -- Remove the DFrame when the animation is over
	end )
end

Output:

AlphaTo Fade Out.gif
Personal tools
Navigation