er2.loadTexture 8
Loads a png/jpg image from the mission folder and returns it as a Texture handle, ready for prop.setAlbedo and any future function that takes a texture.Relative paths are allowed (for example ../SHARED/flags/mine.png) but confined to the folder that contains the missions, exactly like HUD icon files. Images are cached per battle: loading the same file twice costs nothing.
Return value
| Return Type | Description |
|---|---|
| Texture | The texture handle, or nil if the file is missing, outside the missions folder, or not a decodable png/jpg (the console says why). |
Parameters
| Parameter | Type | Description |
|---|---|---|
| 1 | string | Png or jpg file, relative to the mission folder (subfolders and ../SHARED allowed, nothing outside the missions folder). |
Examples
Texture a generic flag prop (texture API)
-- Textures are handles: load one once and pass it around. The same
-- prop works with a faction flag or any image from the mission folder.
local flagTex = er2.getFactionFlag("UnitedStates_allies")
-- local flagTex = er2.loadTexture("flags/my_banner.png")
er2.createProp("FlagWaving_1", vec3(100.0, 25.0, 200.0), vec3(0, 90, 0), false,
function(prop)
prop:setAlbedo(flagTex)
end)
-- In a prop script placed in the mission editor the prop is "myself",
-- and the texture is re-applied automatically when it streams back in:
-- myself:setAlbedo(er2.getFactionFlag("Germany_axis"))Custom banner from the mission folder (texture API)
-- Script assigned to the flag prop in the mission editor: "myself" is
-- this prop. Ship the image with the mission (subfolders are fine).
local bannerTex = er2.loadTexture("flags/clan_banner.png")
if bannerTex == nil then
er2.print("banner image missing!")
return
end
-- the texture sticks: it is re-applied automatically every time the
-- streamed prop comes back into view
myself:setAlbedo(bannerTex)