Texture functions allow you to dynamically change the image an object uses in the scene.
They are shortcuts for assigning or reading obj.image without worrying about full file paths.
setTexture(obj, "file.png")
Changes the object's texture to the specified file.
The file must be located inside the project's assets/images/ folder.
// Change to idle texture
setTexture(player, "PANAMA_IDLE.png");
// Change to walking texture
if (isKeyPressed("ArrowRight")) {
setTexture(player, "PANAMA_walk.png");
}
getTexture(obj)Returns the name of the current texture file (only the filename, without the full path).
console.log(getTexture(player));
// → "PANAMA_IDLE.png"
function Update(obj, dt) {
if (isKeyPressed("w")) {
setTexture(obj, "PANAMA_walk.png");
} else {
setTexture(obj, "PANAMA_IDLE.png");
}
}
setTexture internally builds the full path and loads the image if it is not already cached.getTexture always returns the filename only, without folders.