Garry's Mod Wiki

Derma_Anim

  table Derma_Anim( string name, Panel panel, function func )

Description

Creates a new derma animation.

Arguments

1 string name
Name of the animation to create
2 Panel panel
Panel to run the animation on
3 function func
Function to call to process the animation
Function argument(s):
1 Panel pnl - the panel passed to Derma_Anim
2 table anim - the anim table
3 number delta - the fraction of the progress through the animation
4 any data - optional data passed to the run metatable method

Returns

1 table
A lua metatable containing four methods:
  • Run() - Should be called each frame you want the animation to be ran.
  • Active() - Returns if the animation is currently active (has not finished and stop has not been called)
  • Stop() - Halts the animation at its current progress.
  • Start( Length, Data ) - Prepares the animation to be ran for Length seconds. Must be called once before calling Run(). The data parameter will be passed to the func function.

Example

Applies an easeInQuad easing to the panel to make it glide naturally across the screen.

local function inQuad(fraction, beginning, change) return change * (fraction ^ 2) + beginning end local main = vgui.Create("DFrame") main:SetTitle("Derma_Anim Example") main:SetSize(250, 200) main:SetPos(200) main:MakePopup() local anim = Derma_Anim("EaseInQuad", main, function(pnl, anim, delta, data) pnl:SetPos(inQuad(delta, 200, 600), 300) -- Change the X coordinate from 200 to 200+600 end) anim:Start(2) -- Animate for two seconds main.Think = function(self) if anim:Active() then anim:Run() end end
Output: Panel naturally glides across the screen from 200 x to 800 x