summaryrefslogtreecommitdiffhomepage
path: root/not/Layer.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-09-21 21:05:37 +0200
committerAki <nthirtyone@gmail.com>2017-09-21 21:05:37 +0200
commite9a450d65d4fb564691cdf651ef5771dd88303ae (patch)
treef49d29582dd6877f3b3c807c3f7d9d92d368f798 /not/Layer.lua
parenteb8302723cd85adca0fbaf505cfb315f1db0299a (diff)
parentb97985def64b8bd8f93a7b391b12333595432e52 (diff)
downloadroflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.zip
roflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.tar.gz
roflnauts-e9a450d65d4fb564691cdf651ef5771dd88303ae.tar.bz2
Merge branch 'maps'
Diffstat (limited to 'not/Layer.lua')
-rw-r--r--not/Layer.lua45
1 files changed, 45 insertions, 0 deletions
diff --git a/not/Layer.lua b/not/Layer.lua
new file mode 100644
index 0000000..14dac32
--- /dev/null
+++ b/not/Layer.lua
@@ -0,0 +1,45 @@
+--- 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)
+ self.transformScale = getScale()
+ self.transformRatio = 1
+ self.drawScale = 1
+end
+
+function Layer:delete ()
+ self.canvas = nil
+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:renderTo (func, ...)
+ local c = self:setAsCanvas()
+ func(...)
+ love.graphics.setCanvas(c)
+end
+
+function Layer:renderToWith (camera, func, ...)
+ camera:push()
+ camera:transform(self.transformScale, self.transformRatio, self.canvas:getDimensions())
+ self:renderTo(func, ...)
+ camera:pop()
+end
+
+function Layer:clear ()
+ self:renderTo(love.graphics.clear)
+end
+
+function Layer:draw ()
+ love.graphics.setColor(255, 255, 255, 255)
+ love.graphics.draw(self.canvas, nil, nil, nil, self.drawScale, self.drawScale)
+end
+
+return Layer