Difference between revisions of "RenderTarget"

From GiderosMobile
m
m (Text replacement - "<source" to "<syntaxhighlight")
Line 12: Line 12:
 
=== Example ===
 
=== Example ===
 
'''Using a texture and updating RenderTarget'''
 
'''Using a texture and updating RenderTarget'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
--original bitmap
 
--original bitmap
 
local source = Bitmap.new(Texture.new("crate.png", true))
 
local source = Bitmap.new(Texture.new("crate.png", true))

Revision as of 15:30, 13 July 2023

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2013.06
Inherits from: TextureBase

Description

RenderTarget is a texture on which provided Sprite hierarchy can be rendered.

It can be used in any case in which Texture can be used.

Example

Using a texture and updating RenderTarget <syntaxhighlight lang="lua"> --original bitmap local source = Bitmap.new(Texture.new("crate.png", true))

--render target local rt = RenderTarget.new(source:getWidth(), source:getHeight())

--bitmap with rendertarget as texture local bmp = Bitmap.new(rt) bmp:setPosition(200, 0) stage:addChild(bmp)

--updating source updated Bitmap local frame = 0 stage:addEventListener(Event.ENTER_FRAME, function(event) local r = math.sin(frame * 0.03) * 0.3 + 0.7 local g = math.sin(frame * 0.04) * 0.3 + 0.7 local b = math.sin(frame * 0.05) * 0.3 + 0.7 source:setColorTransform(r, g, b, 1) frame = frame + 1 rt:draw(source) end) </source>

Methods

RenderTarget.new creates a new RenderTarget object
RenderTarget:clear clears rendered texture
RenderTarget:draw renders provided object
RenderTarget:getPixel returns single pixels color and alpha channel
RenderTarget:getPixels returns buffer containing color and alpha data from provided rectangle
RenderTarget:save saves content of RenderTarget as image

Events

Constants