Difference between revisions of "RenderTarget"

From GiderosMobile
Line 29: Line 29:
 
end)</source>
 
end)</source>
 
{|-
 
{|-
| style="width: 50%;"|
+
| style="width: 50%; vertical-align:top;"|
 
=== Methods ===
 
=== Methods ===
[[RenderTarget.new]] {{<translate>Creates new RenderTarget object</translate>}}<br/>
+
[[RenderTarget.new]] ''<translate>Creates new RenderTarget object</translate>''<br/>
[[RenderTarget:clear]] {{<translate>Clears rendered texture</translate>}}<br/>
+
[[RenderTarget:clear]] ''<translate>Clears rendered texture</translate>''<br/>
[[RenderTarget:draw]] {{<translate>Renders provided object</translate>}}<br/>
+
[[RenderTarget:draw]] ''<translate>Renders provided object</translate>''<br/>
[[RenderTarget:getPixel]] {{<translate>Returns single pixels color and alpha channel</translate>}}<br/>
+
[[RenderTarget:getPixel]] ''<translate>Returns single pixels color and alpha channel</translate>''<br/>
[[RenderTarget:getPixels]] {{<translate>Returns buffer containing color and alpha data from provided rectangle</translate>}}<br/>
+
[[RenderTarget:getPixels]] ''<translate>Returns buffer containing color and alpha data from provided rectangle</translate>''<br/>
[[RenderTarget:save]] {{<translate>save contents of RenderTarget as image</translate>}}<br/>
+
[[RenderTarget:save]] ''<translate>save contents of RenderTarget as image</translate>''<br/>
| style="width: 50%;"|
+
| style="width: 50%; vertical-align:top;"|
 
=== Events ===
 
=== Events ===
 
=== Constants ===
 
=== Constants ===
 
|}
 
|}

Revision as of 14:34, 23 August 2018

Supported platforms:
Available since: Gideros 2013.06

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.

Examples

Using as texture and updating RenderTarget

--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)

Methods

RenderTarget.new Creates 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 save contents of RenderTarget as image

Events

Constants