new Texture(path: string, width?: number, height?: number): Texture
Loads an image from a file path. The texture starts loading immediately
but may not be ready until a later frame.For SVG files you can optionally specify render dimensions.
PNG/JPG images always use the dimensions from the file itself — width
and height are ignored.
Param
Type
path
string
Path to the image file
width
number?
Render width for SVG. 0 = auto (proportional to height)
height
number?
Render height for SVG. 0 = auto (proportional to width)
If neither width nor height is provided for an SVG, it renders at
its intrinsic size × 4.
const icon = new Texture("assets/icon.png");// SVG — intrinsic size × 4const svg1 = new Texture("icon.svg");// SVG — exact sizeconst svg2 = new Texture("icon.svg", 128, 128);// SVG — width 256, height proportionalconst svg3 = new Texture("icon.svg", 256);// SVG — height 64, width proportionalconst svg4 = new Texture("icon.svg", 0, 64);
Create textures once outside your render callback - not every
frame. Repeated construction causes repeated disk reads and GPU
uploads.
Correct
Wrong
// Create once at script startconst icon = new Texture("assets/icon.png");// Draw every frameon("render", () => { if (icon.isReady) { Render.image(icon, pos, size, Color.white()); }});
on("render", () => { // BAD: loads from disk every frame! const icon = new Texture("assets/icon.png"); Render.image(icon, pos, size, Color.white());});
const icon = new Texture("assets/weapon.png");on("render", () => { if (!icon.isReady) return; const { success, screen } = Math.worldToScreen(pos); if (success) { Render.image(icon, screen, new Vector2(24, 24), Color.white()); }});
const avatar = new Texture("assets/avatar.png");on("render", () => { if (!avatar.isReady) return; const size = new Vector2(48, 48); Render.imageRounded(avatar, hudPos, size, 24, Color.white()); // rounding = half of width → perfect circle});
const icon = new Texture("assets/shield.png");on("render", () => { if (!icon.isReady) return; // Tint with team color const tint = isAlly ? Color.green() : Color.red(); Render.image(icon, pos, new Vector2(32, 32), tint);});
const logo = new Texture("assets/logo.png");on("render", () => { if (!logo.isReady) return; const drawHeight = 64; const aspect = logo.width / logo.height; const drawWidth = drawHeight * aspect; Render.image(logo, pos, new Vector2(drawWidth, drawHeight), Color.white());});