跳到主要内容

图像(Image)

表示可被 渲染器(Renderer) 绘制的图像资源(image asset)。

type DrawImage = {
myImage: Image?,
sampler: ImageSampler?,
}

function init(self: DrawImage, context: Context): boolean
self.myImage = context:image('myImage')
self.sampler = ImageSampler('clamp', 'clamp', 'bilinear')

return true
end

function draw(self: DrawImage, renderer: Renderer)
if self.myImage and self.sampler then
renderer:drawImage(self.myImage, self.sampler, 'srcOver', 1)
end
end

return function(): Node<DrawImage>
return {
myImage = nil,
sampler = nil,
init = init,
draw = draw,
}
end

字段(Fields)

width

图像宽度(width)。

self.myImage = context:image('myImage')

if self.myImage then
print("myImage width:", self.myImage.width)
end

height

图像高度(height)。

self.myImage = context:image('myImage')

if self.myImage then
print("myImage height:", self.myImage.height )
end