Skip to content
Jérôme Leclercq edited this page Dec 8, 2020 · 2 revisions

API: assets.GetTexture

Description:

Retrieves an handle to a texture file, loading it if necessary. If the texture file cannot be loaded for some reason, this function returns nil.

Prototype:

assets.GetTexture([filepath: string]) -> texture: Texture | nil

Parameters:

  1. filepath: Path to the image file (relative to the resources directory).

Returns:

  1. texture: Handle to the corresponding texture object or nil if the texture couldn't be loaded.

Remarks:

  1. If the texture is not already loaded, it will be loaded during this call (which may take some time).
  2. This function will fail if the image file has not been registered server-side using RegisterClientAssets, independently from the file existence on the host filesystem.
  3. Only the following extensions are supported:
    • bmp
    • dds
    • gif
    • hdr
    • jpg / jpeg
    • pcx
    • pic
    • png
    • ppm
    • pgm
    • psd
    • tga

Example code

A simple script which loads a texture and print its size.

local texture = assets.GetTexture("texture.png")
if (texture) then
	print("Texture size", texture:GetSize())
else
	print("Texture couldn't be loaded")
end

Clone this wiki locally