Skip to main content

DrawTexture

This function was added in DSL 1

Description

Draws a texture on the screen at a specified position and size, with optional color and transparency adjustments.

The texture is defined by a userdata object created with CreateTexture.

info

Keep the general rules of rendering in mind. Use GetTextureDisplayAspectRatio to preserve the aspect ratio of the texture.

The position and size are specified as percentages of the screen dimensions, allowing for flexible placement and scaling. x and y define the top left of the rectangle.

function DrawTexture(texture, x, y, width, height, red, green, blue, alpha) --[[ ... ]] end

Parameters

  • texture: userdata - The texture to draw. This should be a valid texture created with CreateTexture.
  • x: number - The X coordinate of the top-left corner of the rectangle where the texture will be drawn. This value should be between 0 and 1, representing a percentage of the screen width.
  • y: number - The Y coordinate of the top-left corner of the rectangle where the texture will be drawn. This value should be between 0 and 1, representing a percentage of the screen height.
  • width: number - The width of the rectangle where the texture will be drawn. This value should be between 0 and 1, representing a percentage of the screen width.
  • height: number - The height of the rectangle where the texture will be drawn. This value should be between 0 and 1, representing a percentage of the screen height.
  • red?: number - (Optional) The red component of the color to apply to the texture. This value should be between 0 and 255. Defaults to 255.
  • green?: number - (Optional) The green component of the color to apply to the texture. This value should be between 0 and 255. Defaults to 255.
  • blue?: number - (Optional) The blue component of the color to apply to the texture. This value should be between 0 and 255. Defaults to 255.
  • alpha?: number - (Optional) The alpha component of the color to apply to the texture. This value should be between 0 and 255. Defaults to 255.

Return Values

None.

Example

local texture = CreateTexture('path/to/texture.png')
local x, y = 0.5, 0.5
local w, h = 0.2, 0.2
local r, g, b, a = 255, 255, 255, 255
DrawTexture(texture, x, y, w, h, r, g, b, a)

See Also