- Inside Canvas.onPaint() event, you should use this method after drawing operations, surrounded by a previous Canvas.begin() call.
- When drawing operations are executed inside an event or in a Task, Canvas.begin() and Canvas.flip() must be called to preserve the Direct2D drawing state across Tasks.
Canvas:flip() method
Flips the back buffer, displaying it on the Canvas.
Return value
This function returns no value.Example
local ui = require "ui"
require "canvas"
-- create a simple Window
local win = ui.Window("Canvas.flip() sample", "fixed", 320, 200)
-- create a Canvas
local canvas = ui.Canvas(win)
canvas.align = "all"
local x = 160
local y = 100
function win:onKey(key)
if key == "VK_UP" then
y = y - 4
elseif key == "VK_DOWN" then
y = y + 4
elseif key == "VK_LEFT" then
x = x - 4
elseif key == "VK_RIGHT" then
x = x + 4
end
end
function canvas:onPaint()
self:begin()
self:clear()
self:fillcircle(x, y, 5, 0xA0D0A0)
self:flip()
end
ui.run(win):wait()