From 3ced2dbef42d757d02e7ab22c522bdda71042cd0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Fri, 21 Jun 2019 18:27:02 +0200 Subject: [PATCH] fix(world): separate getting data from the internal and advertised view Use two functions instead of just one, one showing the actual dimensions of the internal "cam" (basically, the whole screen), and one showing the advertised displaced camera. Fixes #16 --- CHANGELOG.md | 2 ++ gamecore/modules/world/baseworld.lua | 2 +- gamecore/modules/world/camera.lua | 26 +++++++++++++++++++------- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e79f614..f5b2094 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **examples:** Add missing HUD example for one-player plateformer +- **world:** Separate getting dimensions of the internal and advertised view. + ## 0.5.0 - 2019-06-16 - Meta: Add a Code of Conduct diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index 4bf83eb..db3fbf0 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -413,7 +413,7 @@ function BaseWorld:drawMap(id) if id ~= nil then -- Du à la manière dont fonctionne STI, on est obligé de récupérer les info -- de position de camera pour afficher la carte par rapport à ces infos - tx, ty = self.cameras:getViewCoordinate(id) + tx, ty = self.cameras:getInternalCamCoordinate(id) scale = self.cameras:getViewScale(id) or 1 local vx, vy = self.cameras:getOnScreenViewRelativePosition(id) tx = math.floor(tx - math.abs(vx)) diff --git a/gamecore/modules/world/camera.lua b/gamecore/modules/world/camera.lua index db77abe..3d9023e 100644 --- a/gamecore/modules/world/camera.lua +++ b/gamecore/modules/world/camera.lua @@ -194,15 +194,27 @@ function CameraSystem:detachView(id) end function CameraSystem:getViewCoordinate(id) - local cam = self:getViewCam(id) + local view = self:getView(id) - local camx, camy, camw, camh - camx = cam.x - (self.views.width/2) - camy = cam.y - (self.views.height/2) + local viewx, viewy, vieww, viewh + viewx = view.pos.x - (self.views.width/2) + viewy = view.pos.y - (self.views.height/2) - camw = self.views.width - camh = self.views.height - return camx, camy, camw, camh + vieww = self.views.width + viewh = self.views.height + return viewx, viewy, vieww, viewh +end + +function CameraSystem:getInternalCamCoordinate(id) + local view = self:getView(id) + local cam = self:getViewCam(id) + + local viewx, viewy, vieww, viewh + viewx = cam.x - (self.views.width/2) + viewy = cam.y - (self.views.height/2) + + vieww, viewh = core.screen:getDimensions() + return viewx, viewy, vieww, viewh end function CameraSystem:getOnScreenViewCoordinate(id)