Description
Draws a sprite in 3D space.
This is a rendering function that requires a 3d rendering context.
This means that it will only work in 3d Rendering Hooks.
Arguments
1 Vector positionPosition of the sprite.
2 number widthWidth of the sprite.
3 number heightHeight of the sprite.
4 table color = Color( 255, 255, 255 )Color of the sprite. Uses the
Color.
Example
Draw a sprite at the center of the map
Output: An orange star appears at 0,0,0 on the map.
Example
Function that displays a sprite at the given position, without the need of a specific rendering context
draw.VectorSprite(Vector position, number size, Color color, boolean constantSize)
local toDraw3d
= {}
local sprites3d
= 0
local toDraw2d
= {}
local sprites2d
= 0
local material
= Material(
"sprites/light_ignorez")
function draw.VectorSprite(position, size, color, constantSize)
if (
not isvector(position))
then
error(
"bad argument #1 to draw.DrawVectorSprite (Vector expected, got " .. type(position)
.. ")")
end
if (
not isnumber(size))
then
error(
"bad argument #2 to draw.DrawVectorSprite (number expected, got " .. type(size)
.. ")")
end
if (
not IsColor(color))
then
error(
"bad argument #3 to draw.DrawVectorSprite (Color expected, got " .. type(color)
.. ")")
end
local tbl
= {position, size, color
}
if (constantSize)
then
sprites2d
= sprites2d
+ 1
toDraw2d
[sprites2d
] = tbl
else
sprites3d
= sprites3d
+ 1
toDraw3d
[sprites3d
] = tbl
end
end
local render_SetMaterial
= render.SetMaterial
local render_DrawSprite
= render.DrawSprite
hook.
Add(
"PreDrawEffects",
"draw.VectorSprite",
function()
if (sprites3d
~= 0)
then
render_SetMaterial(material)
for i
= 1, sprites3d
do
local info
= toDraw3d
[i
]
toDraw3d
[i
] = nil
render_DrawSprite(info
[1], info
[2], info
[2], info
[3])
end
sprites3d
= 0
end
end)
local surface_SetMaterial
= surface.SetMaterial
local surface_SetDrawColor
= surface.SetDrawColor
local surface_DrawTexturedRect
= surface.DrawTexturedRect
hook.
Add(
"DrawOverlay",
"draw.VectorSprite",
function()
if (sprites2d
~= 0)
then
surface_SetMaterial(material)
for i
= 1, sprites2d
do
local info
= toDraw2d
[i
]
toDraw2d
[i
] = nil
local pos2d
= info
[1]:
ToScreen()
if pos2d.visible
then
surface_SetDrawColor(info
[3])
surface_DrawTexturedRect(pos2d.x, pos2d.y, info
[2], info
[2])
end
end
sprites2d
= 0
end
end)