类型 表 对象 路径 库 display.* 版本 发行版 2024.3703 关键字 纹理、边界
表示所引用显示对象纹理边界的只读表,具有属性 uMin
、uMax
、vMin
、vMax
。某些着色器可能使用该属性来建立局部坐标系统。
这些值从 0 到 1 之间标准化(与图片集中的像素不同)。既不是网格也不是使用图片的显示对象,其最小值和最大值分别为 0 和 1。
local tex = graphics.newTexture{ type = "canvas", width = 128, height = 128 } local back = display.newRect(0, 0, 128, 128) back:setFillColor(1, 0, 0) local rect = display.newRect(0, 0, 32, 64) rect:setFillColor(0, 0, 1) tex:draw(back) tex:draw(rect) tex:invalidate() local fill = { type = "image", filename = tex.filename, baseDir = tex.baseDir } local function Bounds (object) local bounds = object.path.textureBounds return "Bounds: uMin = " .. bounds.uMin .. ", vMin = " .. bounds.vMin .. ", uMax = " .. bounds.uMax .. ", vMax = " .. bounds.vMax end local vanilla = display.newRect(50, 50, 30, 30) vanilla.fill = fill print("VANILLA RECT") print(Bounds(vanilla)) print("") local polygon = display.newPolygon(150, 120, { 0, -110, 27, -35, 105, -35, 43, 16, 65, 90, 0, 45, -65, 90, -43, 15, -105, -35, -27, -35, }) polygon.fill = fill print("STAR POLYGON") print(Bounds(polygon)) print("") local mesh = display.newMesh{ x = 300, y = 100, mode = "triangles", vertices = { -5, 0, 90, 0, 0, 100, 0, 100, 90, 0, 130, 100, 130, 100, 90, 0, 100, 0 }, uvs = { 0, 0, 0.25, 0, 0, .9, 0, .9, 0.25, 0, 1, .75, 1, .75, 0.25, 0, 1, 0 } } mesh:translate(mesh.path:getVertexOffset()) -- Translate mesh so that vertices have proper world coordinates mesh.fill = fill print("MESH") print(Bounds(mesh)) print("") local options = { frames = { { x = 64 - 16, y = 64 - 32, width = 32, height = 64 } } } local sheet = graphics.newImageSheet(tex.filename, tex.baseDir, options) local image = display.newImage(sheet, 1) image.x, image.y = 500, 100 print("SHEET-BASED IMAGE") print(Bounds(image)) print("") local sprite = display.newSprite(sheet, { name = "state", start = 1, count = 1 }) sprite.x, sprite.y = 600, 150 print("SPRITE FRAME") print(Bounds(sprite))