Garry's Mod Wiki

Revision Difference

ENTITY:Draw#547211

<function name="Draw" parent="ENTITY" type="hook"> <ishook>yes</ishook> <description> Called if and when the entity should be drawn opaquely, based on the <page>Entity:GetRenderGroup</page> of the entity. See <page>Structures/ENT</page> and <page>Enums/RENDERGROUP</page> for more information. See also <page>ENTITY:DrawTranslucent</page>. <note>This function is not called by the game whenever the player looks away from the entity due to optimizations. This will always get called, when define an empty <page>Entity:Think</page> method client-side!</note> <note>This function is not called by the game whenever the player looks away from the entity due to optimizations. To change that, you must define an empty <page>Entity:Think</page> method client-side!</note> </description> <realm>Client</realm> <predicted>No</predicted> <args> <arg name="flags" type="number">The bit flags from <page>Enums/STUDIO</page></arg> </args> </function> <example> <description>Draws the model and makes a rotating text over the entity</description> <code> -- Draw some 3D text local function Draw3DText( pos, ang, scale, text, flipView ) if ( flipView ) then -- Flip the angle 180 degrees around the UP axis ang:RotateAroundAxis( Vector( 0, 0, 1 ), 180 ) end cam.Start3D2D( pos, ang, scale ) -- Actually draw the text. Customize this to your liking. draw.DrawText( text, "Default", 0, 0, Color( 0, 255, 0, 255 ), TEXT_ALIGN_CENTER ) cam.End3D2D() end function ENT:Draw() -- Draw the model self:DrawModel() -- The text to display local text = "Example Text" -- The position. We use model bounds to make the text appear just above the model. Customize this to your liking. local mins, maxs = self:GetModelBounds() local pos = self:GetPos() + Vector( 0, 0, maxs.z + 2 ) -- The angle local ang = Angle( 0, SysTime() * 100 % 360, 90 ) -- Draw front Draw3DText( pos, ang, 0.2, text, false ) -- DrawDraw3DTextback Draw3DText( pos, ang, 0.2, text, true ) end </code> </example> <example> <description>Make sure to always call the <page>Entity:Draw</page> method whenever or not the player looks at the entity</description> <code> function ENT:Draw() self:DrawModel() self:DrawShadow(true) local s = self:GetPos() local e = s + self:GetForward() * 25 render.DrawLine(s, e, color_white) end function ENT:Think() end </code> </example>