From b56cac8e29deac55ceb8cee88dd6233d01370917 Mon Sep 17 00:00:00 2001 From: Pieter Bonne Date: Mon, 4 Nov 2024 22:21:41 +0100 Subject: [PATCH 1/4] Round camera position --- h2d/Camera.hx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/h2d/Camera.hx b/h2d/Camera.hx index c6bf364462..c33ec8fa59 100644 --- a/h2d/Camera.hx +++ b/h2d/Camera.hx @@ -224,8 +224,8 @@ class Camera { matC = scaleY * -sr; matD = scaleY * cr; } - absX = Math.round(-(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX); - absY = Math.round(-(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY); + absX = (-(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX); + absY = (-(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY); invDet = 1 / (matA * matD - matB * matC); posChanged = false; } From 3a240d82d99850849509ade41be111614c41fc97 Mon Sep 17 00:00:00 2001 From: xastor Date: Sun, 10 Nov 2024 09:53:31 +0100 Subject: [PATCH 2/4] Gate behind a define --- h2d/Camera.hx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/h2d/Camera.hx b/h2d/Camera.hx index c33ec8fa59..dc7ada98f0 100644 --- a/h2d/Camera.hx +++ b/h2d/Camera.hx @@ -224,8 +224,13 @@ class Camera { matC = scaleY * -sr; matD = scaleY * cr; } + #if heaps_h2d_enable_camera_rounding + absX = Math.round((-(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX)); + absY = Math.round((-(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY)); + #else absX = (-(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX); absY = (-(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY); + #end invDet = 1 / (matA * matD - matB * matC); posChanged = false; } From 15f393bbbd67d5ed6e6b013cdeffb9320730237b Mon Sep 17 00:00:00 2001 From: xastor Date: Mon, 11 Nov 2024 09:53:26 +0100 Subject: [PATCH 3/4] Refactor to a property --- h2d/Camera.hx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/h2d/Camera.hx b/h2d/Camera.hx index dc7ada98f0..2d53279424 100644 --- a/h2d/Camera.hx +++ b/h2d/Camera.hx @@ -94,6 +94,12 @@ class Camera { **/ public var followRotation : Bool = false; + /** + Round the camera position? + Setting to false allows the camera to have a sub-pixel accurate position. + **/ + public var enableCameraRounding : Bool = true; + var posChanged : Bool; var viewX : Float; @@ -224,13 +230,13 @@ class Camera { matC = scaleY * -sr; matD = scaleY * cr; } - #if heaps_h2d_enable_camera_rounding - absX = Math.round((-(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX)); - absY = Math.round((-(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY)); - #else - absX = (-(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX); - absY = (-(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY); - #end + if (this.enableCameraRounding) { + absX = Math.round((-(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX)); + absY = Math.round((-(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY)); + } else { + absX = -(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX; + absY = -(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY; + } invDet = 1 / (matA * matD - matB * matC); posChanged = false; } From fe22cde8306ac5ca7cc5f4f069f9133f4a386d58 Mon Sep 17 00:00:00 2001 From: xastor Date: Mon, 11 Nov 2024 12:25:25 +0100 Subject: [PATCH 4/4] Simplify the code --- h2d/Camera.hx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/h2d/Camera.hx b/h2d/Camera.hx index 2d53279424..d3a84983ca 100644 --- a/h2d/Camera.hx +++ b/h2d/Camera.hx @@ -230,12 +230,11 @@ class Camera { matC = scaleY * -sr; matD = scaleY * cr; } + absX = -(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX; + absY = -(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY; if (this.enableCameraRounding) { - absX = Math.round((-(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX)); - absY = Math.round((-(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY)); - } else { - absX = -(x * matA + y * matC) + (scene.width * anchorX * viewW) + scene.width * viewX; - absY = -(x * matB + y * matD) + (scene.height * anchorY * viewH) + scene.height * viewY; + absX = Math.round(absX); + absY = Math.round(absY); } invDet = 1 / (matA * matD - matB * matC); posChanged = false;