texture:preload()

类型 函数
对象 TextureResourceBitmap
graphics.*
修订 版本 2024.3703
另请参见 TextureResource
TextureResourceBitmap

概览

创建图像纹理时,将从文件系统读取位图并加载到内存中。当创建的显示对象首次使用该纹理时,将安排将其加载到 GPU。

使用此方法安排在下一个时间步开始前将纹理加载到 GPU。这可能会减少呈现使用纹理的显示对象所需时间。

示例

-- Create "TextureResource" object of type "TextureResourceBitmap"
local texture = graphics.newTexture( { type="image", filename="background.png" } )

-- Pre-load the texture to the GPU
texture:preload()

-- Create display object with the pre-loaded texture
local background = display.newImageRect(
    texture.filename,  -- "filename" property required
    texture.baseDir,   -- "baseDir" property required
    display.contentWidth,
    display.contentHeight
)

-- If you no longer need the texture, release it to prevent memory leaks
texture:releaseSelf()