Skip to content

Commit

Permalink
Merge pull request #1114 from JoeCreates/FlxCameraOffset
Browse files Browse the repository at this point in the history
Added target offset in FlxCamera, #1056
  • Loading branch information
Gama11 committed May 22, 2014
2 parents 5d09a7b + 42d482d commit ade094e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions flixel/FlxCamera.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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(default, null):FlxPoint;
/**
* Used to smoothly track the camera as it follows.
*/
Expand Down Expand Up @@ -414,6 +418,7 @@ class FlxCamera extends FlxBasic

scroll = FlxPoint.get();
followLead = FlxPoint.get();
targetOffset = FlxPoint.get();
_point = FlxPoint.get();
_flashOffset = FlxPoint.get();

Expand Down Expand Up @@ -509,6 +514,7 @@ class FlxCamera extends FlxBasic
#end

scroll = FlxDestroyUtil.put(scroll);
targetOffset = FlxDestroyUtil.put(targetOffset);
deadzone = FlxDestroyUtil.put(deadzone);

target = null;
Expand Down Expand Up @@ -556,13 +562,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)
{
Expand Down Expand Up @@ -630,7 +638,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);
}
}
}
}

Expand Down

0 comments on commit ade094e

Please sign in to comment.