Author Topic: how to make FlxG.follow() "snap" to an integer value?  (Read 1152 times)

BenjaminSantiago

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Benjamin Santiago
Hi y'all! This is the first time posting on this board.

I am using the FlxG.follow() method to make the "camera" object move. I am using an "invisible" FlxObject because I don't want the camera to straight up "follow" something, I'd like it to "tween" to a new coordinate. In this particular case, I am just moving an entire "screen" up or down. So my stage is 360 by 240 and I have four images. If the camera is at 0,0, and I click to go up it will go to 0,-240 and reveal another image. The problem I am having is that when the "tween" to the new coordinate it looks like it is not snapping to the final value. So if it's supposed to go to -240 it looks like it is stuck at -239.999999999.. and I am still seeing a sliver of the previous image. This isn't horrible, but when I click again it will snap to said final value.

Do I have to overwrite the follow() function or something? Is there somewhere to put a Math.round() I'm not aware of?

Any and all help is appreciated, Thanks!

Adam Atomic

  • Founder
  • Key Contributor
  • *****
  • Posts: 852
  • Karma: +0/-0
  • new dad
    • View Profile
    • Adam Atomic
Re: how to make FlxG.follow() "snap" to an integer value?
« Reply #1 on: Tue, Apr 26, 2011 »
Floating point errors suck :( v2.50 has a lot of +0.0000001s added to things all over th place in an attempt to curtail those effects withoutnhaving to call round() everywhere... In the meantime, you could try teed ing to 240.0000001 or something... It's gross, but it should prevent those awful annoying floating point errors.  You can also directly manipulate and adjust FlxG.scroll in all versions of flixel, so you could just manually round that value when the tween finishes maybe?

BenjaminSantiago

  • New Member
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
    • Benjamin Santiago
Re: how to make FlxG.follow() "snap" to an integer value?
« Reply #2 on: Tue, Apr 26, 2011 »
Ahhh from the man himself! Awesome. adding .000000000000000000000000000001 isn't too terrible for now. I'd actually prefer that, for now as I'm getting my feet wet with flixel and also weening myself off the flash ide so making everything pretty isn't the biggest deal to me
Thank you so much Mr. Atomic