From 5d0bba608fe420e6dd52d4778cd788819bf9e452 Mon Sep 17 00:00:00 2001 From: Joe Williamson Date: Wed, 20 Jul 2016 01:42:12 +0100 Subject: [PATCH] Adjust camera scroll bounds to account for zoom --- flixel/FlxCamera.hx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index eb4e9a86ab..242847722f 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -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 = minScrollX == null ? null : minScrollX - (zoom - 1) * width / (2 * zoom); + var maxX:Null = maxScrollX == null ? null : maxScrollX + (zoom - 1) * width / (2 * zoom); + var minY:Null = minScrollY == null ? null : minScrollY - (zoom - 1) * height / (2 * zoom); + var maxY:Null = 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, (maxScrollX != null) ? maxX - width : null); + scroll.y = FlxMath.bound(scroll.y, minY, (maxScrollY != null) ? maxY - height : null); } /**