Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions h2d/Camera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -224,8 +230,12 @@ 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;
if (this.enableCameraRounding) {
absX = Math.round(absX);
absY = Math.round(absY);
}
invDet = 1 / (matA * matD - matB * matC);
posChanged = false;
}
Expand Down