summaryrefslogtreecommitdiffhomepage
path: root/not/Layer.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-08 15:59:39 +0200
committerAki <nthirtyone@gmail.com>2017-09-08 15:59:39 +0200
commit5ef20afaf6a9aca1999faf8904594d94fcfaaa66 (patch)
treea41526816a95d4f1ae35c714cd9a462fb6ee4d68 /not/Layer.lua
parentcff3a516083df2e43f6936812baba56a622d804a (diff)
downloadroflnauts-5ef20afaf6a9aca1999faf8904594d94fcfaaa66.zip
roflnauts-5ef20afaf6a9aca1999faf8904594d94fcfaaa66.tar.gz
roflnauts-5ef20afaf6a9aca1999faf8904594d94fcfaaa66.tar.bz2
Created Layer class
Diffstat (limited to 'not/Layer.lua')
-rw-r--r--not/Layer.lua27
1 files changed, 27 insertions, 0 deletions
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