Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust camera scroll bounds to account for zoom #1889

Merged
merged 1 commit into from
Aug 21, 2016
Merged
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
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