父级 TextureResource 库 graphics.* 修订版 发行版 2024.3703 关键字 纹理、性能优化、纹理内存、图像 另请参见 graphics.newTexture() TextureResource TextureResourceBitmap texture.type
当指定的 类型 为 "canvas"
时,由 graphics.newTexture() 创建的对象。此纹理资源是一个
local tex = graphics.newTexture( { type="canvas", width=128, height=128 } ) -- Create display object with texture as contents local rect = display.newImageRect( tex.filename, -- "filename" property required tex.baseDir, -- "baseDir" property required display.contentWidth, display.contentHeight ) rect.x = display.contentCenterX rect.y = display.contentCenterY -- Set background color to be applied if texture is cleared tex:setBackground( 0, 0, 1 ) -- Create a circle and draw/render it to the texture local circ = display.newCircle( 0, 0, 64 ) circ:setFillColor( { type="gradient", color1={0,0.2,1}, color2={0.8,0.8,0.8}, direction="down" } ) tex:draw( circ ) -- Create a polygon and draw/render it to the texture local poly = display.newPolygon( 0, 0, {0,-55,14,-18,52,-18,22,8,32,45,0,22,-32,45,-22,8,-52,-18,-14,-18} ) poly:setFillColor( 0.2, 1, 0.2 ) tex:draw( poly ) -- Schedule texture objects to be rendered to texture before next frame tex:invalidate() -- Function to restore texture on resume local function onSystemEvent( event ) if ( event.type == "applicationResume" ) then tex:invalidate( "cache" ) end end -- Set up a system event listener Runtime:addEventListener( "system", onSystemEvent )