Author Topic: Fix for jittery camera movement (Flixel 2.5)  (Read 8979 times)

krix

  • Member
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
Fix for jittery camera movement (Flixel 2.5)
« on: Wed, Jun 29, 2011 »
I figured out how to fix the jittery camera movement that occurs when the camera is following an object.

You'll have to adjust the targetX and targetY variables in the update() function of FlxCamera from this:
Code: [Select]
var targetX:Number = target.x + ((target.x > 0)?0.0000001:-0.0000001);
var targetY:Number = target.y + ((target.y > 0)?0.0000001:-0.0000001);

to this:
Code: [Select]
var targetX:Number = FlxU.ceil(target.x + ((target.x > 0)?0.0000001:-0.0000001));
var targetY:Number = FlxU.ceil(target.y + ((target.y > 0)?0.0000001:-0.0000001));

Here is a github link of the change:
https://github.com/krix/flixel/commit/d08623d0013cbd21c98880655c2bc94017f09d7c

Here is the fixed FlxCamera.as:
https://github.com/krix/flixel/blob/master/org/flixel/FlxCamera.as


This instantly made the camera movement in my game super smooth!
I hope this helps some of you, too.

Cheers,
Dirk

[EDIT]
I realized that this wasn't working if the camera style "lockon" was used. So I updated my fix. I also assembled a small demo to show the new smoothness:
GitHub link to the demo
Link to the playable demo
« Last Edit: Mon, Jul 4, 2011 by krix »

felipe

  • Member
  • **
  • Posts: 36
  • Karma: +0/-0
  • games!
    • View Profile
    • i love pixel
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #1 on: Sat, Jul 9, 2011 »
Thanks a lot, I was really having trouble with that problem

John Hutchinson (Johntron247)

  • Commodore 256
  • Contributor
  • ****
  • Posts: 392
  • Karma: +1/-0
  • I can has lazerz?
    • View Profile
    • Level X Games
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #2 on: Sat, Jul 16, 2011 »
Thanks!  My game is REALLY fast paced and this helped make the camera movement look as nice-looking as possible.  I also lowered the game framerate to better match the flash framerate (30/30) and that helped quite a bit.  It looks very smooth now and I see no noticable difference between 60fps and 30fps = definitely worth the tradeoff.

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #3 on: Tue, Aug 2, 2011 »
Just to confirm....

This fix :
var targetX:Number = FlxU.ceil(target.x + ((target.x > 0)?0.0000001:-0.0000001));
var targetY:Number = FlxU.ceil(target.y + ((target.y > 0)?0.0000001:-0.0000001));

Works for lockon as well ?

krix

  • Member
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #4 on: Tue, Aug 2, 2011 »
Just to confirm....

This fix :
var targetX:Number = FlxU.ceil(target.x + ((target.x > 0)?0.0000001:-0.0000001));
var targetY:Number = FlxU.ceil(target.y + ((target.y > 0)?0.0000001:-0.0000001));

Works for lockon as well ?

Nope, you have to make some more changes to make this work with the "lockon" style.
Take a look at the FlxCamera.as I posted earlier.

Cheers,
Dirk

Arkeus

  • Contributor
  • ****
  • Posts: 321
  • Karma: +1/-0
    • View Profile
    • I, Arkeus
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #5 on: Fri, Aug 12, 2011 »
Nope, you have to make some more changes to make this work with the "lockon" style.
Take a look at the FlxCamera.as I posted earlier.

Cheers,
Dirk

I upgraded to yours, and I wanted to mention that the documentation for the follow method says to set it to null to not follow anything, but that throws a null pointer exception is your follow style is currently set to STYLE_LOCKON because you try to access the targets width and height. Probably a bug, so wanted to mention it.

krix

  • Member
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #6 on: Mon, Aug 15, 2011 »
I upgraded to yours, and I wanted to mention that the documentation for the follow method says to set it to null to not follow anything, but that throws a null pointer exception is your follow style is currently set to STYLE_LOCKON because you try to access the targets width and height. Probably a bug, so wanted to mention it.

Hey you're right, thanks for pointing that out.
I uploaded a fixed version to github.

https://github.com/krix/flixel/blob/master/org/flixel/FlxCamera.as

Cheers,
Dirk

dplucenio

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #7 on: Mon, Nov 21, 2011 »
Thanks a lot Krix.
Unfortunatelly it seems this does not fix camera follow for rotated sprites (I'm using these a lot in a space shooter prototype).
I tried your code example rotating the player. It's still "shaking". I guess I don't need to put the code here, it's easy to implement by just repeating what i said right?
Any idea of how could we fix that?
« Last Edit: Mon, Nov 21, 2011 by dplucenio »

krix

  • Member
  • **
  • Posts: 61
  • Karma: +0/-0
    • View Profile
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #8 on: Tue, Nov 22, 2011 »
Thanks a lot Krix.
Unfortunatelly it seems this does not fix camera follow for rotated sprites (I'm using these a lot in a space shooter prototype).
I tried your code example rotating the player. It's still "shaking". I guess I don't need to put the code here, it's easy to implement by just repeating what i said right?
Any idea of how could we fix that?

Hi dplucenio,
Thanks for testing this. I looked into your problem and found a way to fix it.
Have a look at my updated demo-project: https://github.com/krix/CameraScrollFix
The changes are also in my flixel fork: https://github.com/krix/flixel

It should now work fine for sprites with simple and advanced rendering.
As for rotations you have to use bakedRotations to get a good result.
I hope this helps you solve your problem.

Cheers,
Dirk

c023-DeV

  • Game Artisan
  • Active Member
  • ***
  • Posts: 176
  • Karma: +0/-0
    • View Profile
    • DeV-ZoO
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #9 on: Fri, Nov 25, 2011 »
Hi,

when I use this fix then the bullets of my Powertools Bullets get stuck in the air when I'm moving about, could that be an issue?

Edit:

It works when I just set the:
Code: [Select]
var targetX:Number = FlxU.ceil(target.x + ((target.x > 0)?0.0000001:-0.0000001));
var targetY:Number = FlxU.ceil(target.y + ((target.y > 0)?0.0000001:-0.0000001));
« Last Edit: Fri, Nov 25, 2011 by c023-DeV »
If you aint got no dedication, you won't get no education!

pixelomatic

  • Active Member
  • ***
  • Posts: 131
  • Karma: +0/-0
    • View Profile
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #10 on: Sat, Dec 31, 2011 »
Flixel 2.3 camera was better which had a built-in lerp function. I guess we can still achieve same functionality but we have to do it our own way.

paala

  • Contributor
  • ****
  • Posts: 250
  • Karma: +0/-1
    • View Profile
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #11 on: Sat, Feb 23, 2013 »
This doesn't fix at all. Even in the demo the camera movement is still jerky.

Gama11

  • Contributor
  • ****
  • Posts: 390
  • Karma: +0/-0
    • View Profile
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #12 on: Sun, Feb 24, 2013 »
This doesn't fix at all. Even in the demo the camera movement is still jerky.

Hm... Might be something on your end then? The camera movement in that demo seems perfectly smooth to me.

paala

  • Contributor
  • ****
  • Posts: 250
  • Karma: +0/-1
    • View Profile
Re: Fix for jittery camera movement (Flixel 2.5)
« Reply #13 on: Sun, Feb 24, 2013 »
I think the problem at my side is screen tearing which is discuss here:
http://forums.flixel.org/index.php?topic=4247.0
And this problem is flixel independent but i don't know why in my games at flixel 2.43 vs 2.5  the screen tearing and v sync problems were less visible.