From 5ef20afaf6a9aca1999faf8904594d94fcfaaa66 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 8 Sep 2017 15:59:39 +0200 Subject: Created Layer class --- not/Layer.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 not/Layer.lua (limited to 'not/Layer.lua') diff --git a/not/Layer.lua b/not/Layer.lua new file mode 100644 index 0000000..db16175 --- /dev/null +++ b/not/Layer.lua @@ -0,0 +1,27 @@ +--- A little bit more than just a Canvas. +Layer = require "not.Object":extends() + +function Layer:new (width, height) + self.canvas = love.graphics.newCanvas(width, height) +end + +--- Sets this layer as current canvas for drawing with love.graphics functions. +-- @return old canvas used by love +function Layer:setAsCanvas () + local c = love.graphics.getCanvas() + love.graphics.setCanvas(self.canvas) + return c +end + +function Layer:clear () + local c = self:setAsCanvas() + love.graphics.clear() + love.graphics.setCanvas(c) +end + +function Layer:draw () + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(self.canvas) +end + +return Layer -- cgit v1.1