From e9471c00d26232dab7ada8536af6416bcbd9c7e6 Mon Sep 17 00:00:00 2001 From: huruey Date: Wed, 21 May 2014 06:45:52 +0100 Subject: [PATCH 1/2] Added target offset in FlxCamera --- flixel/FlxCamera.hx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 1da856619e..2f15074b57 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -57,6 +57,10 @@ class FlxCamera extends FlxBasic * Tells the camera to follow this FlxObject object around. */ public var target:FlxObject; + /** + * Offset the camera target + */ + public var targetOffset:FlxPoint; /** * Used to smoothly track the camera as it follows. */ @@ -414,6 +418,7 @@ class FlxCamera extends FlxBasic scroll = FlxPoint.get(); followLead = FlxPoint.get(); + targetOffset = FlxPoint.get(); _point = FlxPoint.get(); _flashOffset = FlxPoint.get(); @@ -556,13 +561,15 @@ class FlxCamera extends FlxBasic //or doublecheck our deadzone and update accordingly. if (deadzone == null) { - focusOn(target.getMidpoint(_point)); + target.getMidpoint(_point); + _point.addPoint(targetOffset); + focusOn(_point); } else { var edge:Float; - var targetX:Float = target.x; - var targetY:Float = target.y; + var targetX:Float = target.x + targetOffset.x; + var targetY:Float = target.y + targetOffset.y; if (style == SCREEN_BY_SCREEN) { @@ -630,7 +637,7 @@ class FlxCamera extends FlxBasic { scroll.x += (_scrollTarget.x - scroll.x) * FlxG.elapsed / (FlxG.elapsed + followLerp * FlxG.elapsed); scroll.y += (_scrollTarget.y - scroll.y) * FlxG.elapsed / (FlxG.elapsed + followLerp * FlxG.elapsed); - } + } } } From 42d482d75567e9758cd6ea835dde800ab55e717b Mon Sep 17 00:00:00 2001 From: Joe Williamson Date: Wed, 21 May 2014 07:57:36 +0100 Subject: [PATCH 2/2] targetOffset is now read only and gets destroyed --- flixel/FlxCamera.hx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flixel/FlxCamera.hx b/flixel/FlxCamera.hx index 2f15074b57..720f760a6b 100644 --- a/flixel/FlxCamera.hx +++ b/flixel/FlxCamera.hx @@ -60,7 +60,7 @@ class FlxCamera extends FlxBasic /** * Offset the camera target */ - public var targetOffset:FlxPoint; + public var targetOffset(default, null):FlxPoint; /** * Used to smoothly track the camera as it follows. */ @@ -514,6 +514,7 @@ class FlxCamera extends FlxBasic #end scroll = FlxDestroyUtil.put(scroll); + targetOffset = FlxDestroyUtil.put(targetOffset); deadzone = FlxDestroyUtil.put(deadzone); target = null;