Difference between revisions of "Canvas:renderTo"
(Add complete example.) |
(changed 255 color range to 1) |
||
Line 30: | Line 30: | ||
function love.update() | function love.update() | ||
canvas:renderTo(function() | canvas:renderTo(function() | ||
− | love.graphics.setColor(love.math.random( | + | love.graphics.setColor(love.math.random(), 0, 0); |
love.graphics.line(0, 0, love.math.random(0, love.graphics.getWidth()), love.math.random(0, love.graphics.getHeight())); | love.graphics.line(0, 0, love.math.random(0, love.graphics.getWidth()), love.math.random(0, love.graphics.getHeight())); | ||
end); | end); | ||
Line 36: | Line 36: | ||
function love.draw() | function love.draw() | ||
− | love.graphics.setColor( | + | love.graphics.setColor(1, 1, 1); |
love.graphics.draw(canvas); | love.graphics.draw(canvas); | ||
end | end |
Revision as of 15:33, 10 January 2020
Available since LÖVE 0.8.0 |
It has been renamed from Framebuffer:renderTo. |
Render to the Canvas using a function.
This is a shortcut to love.graphics.setCanvas:
canvas:renderTo( func )
is the same as
love.graphics.setCanvas( canvas )
func()
love.graphics.setCanvas()
Contents
Function
Synopsis
Canvas:renderTo( func )
Arguments
function func
- A function performing drawing operations.
Returns
Nothing.
Examples
Using an anonymous function for drawing to a Canvas
This example randomly draws a bunch of red lines from the top left corner of the screen to the bottom.
local canvas = love.graphics.newCanvas()
function love.update()
canvas:renderTo(function()
love.graphics.setColor(love.math.random(), 0, 0);
love.graphics.line(0, 0, love.math.random(0, love.graphics.getWidth()), love.math.random(0, love.graphics.getHeight()));
end);
end
function love.draw()
love.graphics.setColor(1, 1, 1);
love.graphics.draw(canvas);
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info