类型 字符串 对象 TextureResource 库 graphics.* 修订 版本 2024.3703 另请参阅 texture.baseDir texture.type TextureResource
使用此属性而不是真实文件名来创建显示对象、填充,并在其他需要真实图像文件名的地方使用。在这些情况下,您还必须将 texture.baseDir 作为参数传递 — 请参阅下面的示例以作参考。
此"background.png" 指定为纹理的 filename,请勿尝试在 system.pathForFile() 中使用 texture.filename 作为对同一文件的引用。本质上,此属性指的是内部内存,而不是文件系统。
-- Standard image
local image1 = display.newImageRect( "background.png", 100, 100 )
image1.x = 100
image1.y = 100
-- TextureResource-based image
local texture = graphics.newTexture( { type="image", filename="background.png" } )
local image2 = display.newImageRect(
texture.filename, -- "filename" property required
texture.baseDir, -- "baseDir" property required
100,
100
)
image2.x = 200
image2.y = 100
-- Standard fill
local circle1 = display.newCircle( 100, 100, 50 )
circle1.fill = {
type = "image",
filename = "background.png"
}
-- TextureResource-based fill
local texture = graphics.newTexture( { type="image", filename="background.png" } )
local circle2 = display.newCircle( 200, 100, 50 )
circle2.fill = {
type = "image",
filename = texture.filename, -- "filename" property required
baseDir = texture.baseDir -- "baseDir" property required
}