Skip to content

Commit

Permalink
Fix FlxCamera jitters when following a target
Browse files Browse the repository at this point in the history
Resolves the following issue:
 * FlixelCommunity#5 - AdamAtomic#227

Fix provided by [Krix](https://github.com/krix)
  • Loading branch information
Dirk Bunk (Krix) authored and IQAndreas committed Dec 31, 2012
1 parent 63973b0 commit 0e09cfb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
19 changes: 17 additions & 2 deletions org/flixel/FlxCamera.as
Expand Up @@ -302,6 +302,12 @@ package org.flixel
var targetX:Number = target.x + ((target.x > 0)?0.0000001:-0.0000001);
var targetY:Number = target.y + ((target.y > 0)?0.0000001:-0.0000001);

if (FlxSprite(target).simpleRender)
{
targetX = FlxU.ceil(targetX);
targetY = FlxU.ceil(targetY);
}

edge = targetX - deadzone.x;
if(scroll.x > edge)
scroll.x = edge;
Expand Down Expand Up @@ -381,11 +387,14 @@ package org.flixel
{
target = Target;
var helper:Number;
var w:Number = 0;
var h:Number = 0;

switch(Style)
{
case STYLE_PLATFORMER:
var w:Number = width/8;
var h:Number = height/3;
w = width/8;
h = height/3;
deadzone = new FlxRect((width-w)/2,(height-h)/2 - h*0.25,w,h);
break;
case STYLE_TOPDOWN:
Expand All @@ -397,6 +406,12 @@ package org.flixel
deadzone = new FlxRect((width-helper)/2,(height-helper)/2,helper,helper);
break;
case STYLE_LOCKON:
if (target != null) {
w = target.width;
h = target.height;
}
deadzone = new FlxRect((width-w)/2,(height-h)/2 - h * 0.25,w,h);
break;
default:
deadzone = null;
break;
Expand Down
15 changes: 11 additions & 4 deletions org/flixel/FlxSprite.as
Expand Up @@ -155,6 +155,13 @@ package org.flixel
*/
protected var _matrix:Matrix;

/**
* If the Sprite is beeing rendered in simple mode.
*/
public function get simpleRender():Boolean {
return ((angle == 0) || (_bakedRotation > 0)) && (scale.x == 1) && (scale.y == 1) && (blend == null)
}

/**
* Creates a white 8x8 square <code>FlxSprite</code> at the specified position.
* Optionally can load a simple, one-frame graphic instead.
Expand Down Expand Up @@ -442,11 +449,11 @@ package org.flixel
camera = cameras[i++];
if(!onScreen(camera))
continue;
_point.x = x - int(camera.scroll.x*scrollFactor.x) - offset.x;
_point.y = y - int(camera.scroll.y*scrollFactor.y) - offset.y;
_point.x = x - int(camera.scroll.x*scrollFactor.x) - FlxU.floor(offset.x);
_point.y = y - int(camera.scroll.y*scrollFactor.y) - FlxU.floor(offset.y);
_point.x += (_point.x > 0)?0.0000001:-0.0000001;
_point.y += (_point.y > 0)?0.0000001:-0.0000001;
if(((angle == 0) || (_bakedRotation > 0)) && (scale.x == 1) && (scale.y == 1) && (blend == null))
if(simpleRender)
{ //Simple render
_flashPoint.x = _point.x;
_flashPoint.y = _point.y;
Expand Down Expand Up @@ -917,4 +924,4 @@ package org.flixel
dirty = false;
}
}
}
}

0 comments on commit 0e09cfb

Please sign in to comment.