Skip to content

Commit

Permalink
Adjust camera scroll bounds to account for zoom (#1889)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeCreates authored and Gama11 committed Aug 21, 2016
1 parent 5e1de31 commit 0f6ac6d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -872,9 +872,15 @@ class FlxCamera extends FlxBasic
*/
public function updateScroll():Void
{
//Make sure we didn't go outside the camera's bounds
scroll.x = FlxMath.bound(scroll.x, minScrollX, (maxScrollX != null) ? maxScrollX - width : null);
scroll.y = FlxMath.bound(scroll.y, minScrollY, (maxScrollY != null) ? maxScrollY - height : null);
// Adjust bounds to account for zoom
var minX:Null<Float> = minScrollX == null ? null : minScrollX - (zoom - 1) * width / (2 * zoom);
var maxX:Null<Float> = maxScrollX == null ? null : maxScrollX + (zoom - 1) * width / (2 * zoom);
var minY:Null<Float> = minScrollY == null ? null : minScrollY - (zoom - 1) * height / (2 * zoom);
var maxY:Null<Float> = maxScrollY == null ? null : maxScrollY + (zoom - 1) * height / (2 * zoom);

// Make sure we didn't go outside the camera's bounds
scroll.x = FlxMath.bound(scroll.x, minX, (maxX != null) ? maxX - width : null);
scroll.y = FlxMath.bound(scroll.y, minY, (maxY != null) ? maxY - height : null);
}

/**
Expand Down

0 comments on commit 0f6ac6d

Please sign in to comment.