From 9e29f6127fc27e58a5680a8aa6bea7336add4755 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 03:34:23 +0200 Subject: Added renderToWith to shorten using Camera with Layers --- not/Layer.lua | 10 ++++++++++ not/World.lua | 12 ++---------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'not') diff --git a/not/Layer.lua b/not/Layer.lua index 126b402..6be61c4 100644 --- a/not/Layer.lua +++ b/not/Layer.lua @@ -3,6 +3,8 @@ Layer = require "not.Object":extends() function Layer:new (width, height) self.canvas = love.graphics.newCanvas(width, height) + self.scale = false + self.ratio = false end function Layer:delete () @@ -23,6 +25,14 @@ function Layer:renderTo (func, ...) love.graphics.setCanvas(c) end +function Layer:renderToWith (camera, func, ...) + camera:push() + camera:scale(self.scale) + camera:translate(self.ratio) + self:renderTo(func, ...) + camera:pop() +end + function Layer:clear () self:renderTo(love.graphics.clear) end diff --git a/not/World.lua b/not/World.lua index 37b6dbe..d7b69b2 100644 --- a/not/World.lua +++ b/not/World.lua @@ -260,18 +260,10 @@ function World:draw () -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do if entity.draw and entity.layer then - self.camera:push() - self.camera:scale(entity.layer.scale) - self.camera:translate(entity.layer.ratio) - entity.layer:renderTo(entity.draw, entity, 0, 0, 1, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. - self.camera:pop() + entity.layer:renderToWith(self.camera, entity.draw, entity, 0, 0, 1, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. end if entity.drawTag then - self.camera:push() - self.camera:scale() - self.camera:translate() - self.layers[6]:renderTo(entity.drawTag, entity, 0, 0, 1) -- TODO: Offsets and Scale passed. See `World@draw`. - self.camera:pop() + self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, 0, 0, 1) -- TODO: Offsets and Scale passed. See `World@draw`. end end -- cgit v1.1