texture.baseDir

类型 目录常量
对象 TextureResource
graphics.*
修订版本 版本 2024.3703
另请参阅 texture.filename
texture.type
TextureResource

概述

使用此属性代替实际的目录常量来创建显示对象、填充,并在其他需要实际目录常量的地方使用。在这些情况下,您还必须将 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
}