From 0913693cde5fb74db76b2d283787ffb6a4d794ec Mon Sep 17 00:00:00 2001 From: xgoff Date: Sat, 4 Aug 2012 02:17:29 -0500 Subject: zero-argument version of canvas:clear() is much faster now --- fakecanvas.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'fakecanvas.lua') diff --git a/fakecanvas.lua b/fakecanvas.lua index c311b7e..863dca7 100644 --- a/fakecanvas.lua +++ b/fakecanvas.lua @@ -50,11 +50,13 @@ local options = { vflip = true, } +local blank function canvas:clear (...) -- other option is chucking out the imagedata and creating a new one, but i'd probably end up using mapPixel anyway local nargs = select("#", ...) if nargs == 0 then - canvases[self]._imagedata:mapPixel(function () return 0, 0, 0, 0 end) + local id = canvases[self]._imagedata + id:paste(blank, 0, 0, 0, 0, id:getWidth(), id:getHeight()) elseif nargs == 1 and type(...) == "table" then local t = ... local r, g, b, a = tonumber(t[1]) or 0, tonumber(t[2]) or 0, tonumber(t[3]) or 0, tonumber(t[4]) or 255 @@ -318,6 +320,8 @@ function M.getOption (name) return options[name] end +blank = love.image.newImageData(M.getMaxCanvasSize()) + M.enable() return M \ No newline at end of file -- cgit v1.2.3-54-g00ecf