From f34ec5f8f29ce07d69104e537e87ed357abaf786 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 12:50:46 +0200 Subject: Camera and Layers now properly handle different resolution ratios --- not/Camera.lua | 55 ++++++++++--------------------------------------------- 1 file changed, 10 insertions(+), 45 deletions(-) (limited to 'not/Camera.lua') diff --git a/not/Camera.lua b/not/Camera.lua index b3b8128..65395cb 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -1,5 +1,5 @@ --- Used in drawing other stuff in places. --- TODO: Support for real scale translations. +-- TODO: Camera is missing documentation on every important method. Camera = require "not.Object":extends() Camera.SHAKE_LENGTH = 0.6 @@ -26,41 +26,19 @@ function Camera:push () love.graphics.push() end -function Camera:scale (scale) - scale = scale or getScale() - love.graphics.scale(scale, scale) -end - -function Camera:translate (ratio) +function Camera:transform (scale, ratio, vw, vh) local px, py = self:getPosition() - local dx, dy = self:getShake() - local ox, oy = self:getHalfViewSize() - if ratio then - dx = dx * ratio - dy = dy * ratio - px = px * ratio - py = py * ratio - end - love.graphics.translate(ox - px - dx, oy - py - dy) -end + local sx, sy = self:getShake() + local dx, dy = (px + sx) * ratio, (py + sy) * ratio --- TODO: TranslateReal is temporary. -function Camera:translateReal (ratio) - local px, py = self:getPosition() - local dx, dy = self:getShake() - local ox, oy = self:getHalfViewSize(getRealScale()) - if ratio then - dx = dx * ratio - dy = dy * ratio - px = px * ratio - py = py * ratio - end - love.graphics.translate(ox - px - dx, oy - py - dy) + vw, vh = vw / scale / 2, vh / scale / 2 + + love.graphics.scale(scale, scale) + love.graphics.translate(vw - dx, vh - dy) end function Camera:pop () love.graphics.pop() - self._scale = nil end function Camera:setPosition (x, y) @@ -73,25 +51,12 @@ function Camera:getPosition () return self.x, self.y end -function Camera:getBoundaries () +function Camera:getBoundaries (scale, vw, vh) local x, y = self:getPosition() - local width, height = self:getHalfViewSize() + local width, height = vw / scale / 2, vh / scale / 2 return x - width, y - height, x + width, y + height end --- TODO: Review getViewSize of Camera. -function Camera:getViewSize (scale) - scale = scale or getScale() - local width = love.graphics.getWidth() / scale - local height = love.graphics.getHeight() / scale - return width, height -end - -function Camera:getHalfViewSize (scale) - local width, height = self:getViewSize(scale) - return width / 2, height / 2 -end - function Camera:startShake () self.shakeTime = Camera.SHAKE_LENGTH end -- cgit v1.1