From 1c8c2d6937b2dea434e92aad4029d514f7430151 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 14 Jul 2019 15:51:58 +0200 Subject: [PATCH] feat(screen): add a way to get coordinate and scale --- CHANGELOG.md | 2 ++ gamecore/libs/cscreen.lua | 8 ++++++++ gamecore/screen.lua | 8 ++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7497702..22007f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **examples:** Test all player number and camera types +- **core.screen:** Add a way to get coordinate and scale + ### Changed - **world2D:** Use a list for bodies (hitboxes, etc) and one other for actors diff --git a/gamecore/libs/cscreen.lua b/gamecore/libs/cscreen.lua index 579ea0d..e8c3243 100644 --- a/gamecore/libs/cscreen.lua +++ b/gamecore/libs/cscreen.lua @@ -87,6 +87,14 @@ function CScreen.project(x, y) return math.floor((x - tx) / fsv), math.floor((y - ty) / fsv) end +function CScreen.getScale() + return fsv +end + +function CScreen.getScreenCoordinate(x, y) + return math.floor((x + tx) * fsv), math.floor((y + ty) * fsv) +end + -- Change letterbox color function CScreen.setColor(r, g, b, a) cr = r diff --git a/gamecore/screen.lua b/gamecore/screen.lua index ec3e6e0..fe23c7c 100644 --- a/gamecore/screen.lua +++ b/gamecore/screen.lua @@ -66,6 +66,14 @@ function ScreenManager:getMousePosition() return CScreen.project(love.mouse.getX(), love.mouse.getY()) end +function ScreenManager:getScale() + return CScreen.getScale() +end + +function ScreenManager:getScreenCoordinate(x, y) + return CScreen.getScreenCoordinate(x, y) +end + -- INFO FUNCTIONS -- Get screen informations