Panel/AlphaTo

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m (It is better to use "self" argument instead of repeating name)
Line 40: Line 40:
 
DermaButton:SetPos( 25, 40 )
 
DermaButton:SetPos( 25, 40 )
 
DermaButton:SetSize( 250, 50 )
 
DermaButton:SetSize( 250, 50 )
DermaButton.DoClick = function()
+
DermaButton.DoClick = function(self)
DermaPanel:AlphaTo( 0, 1, 0, function()
+
self:AlphaTo( 0, 1, 0, function()
DermaPanel:Remove() -- Remove the DFrame when the animation is over
+
self:Remove() -- Remove the DFrame when the animation is over
 
end )
 
end )
 
end
 
end
 
|Output=[[Image:AlphaTo_Fade_Out.gif‎]]
 
|Output=[[Image:AlphaTo_Fade_Out.gif‎]]
 
}}
 
}}

Revision as of 16:12, 17 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(self)
	self:AlphaTo( 0, 1, 0, function() 	
		self:Remove() -- Remove the DFrame when the animation is over
	end )
end

Output:

AlphaTo Fade Out.gif
Personal tools
Navigation