Hello I'm new to Haxe/HaxeFlixel. I'm having a strange issue with FlxG.camera.zoom. I'm trying to define a range in which a user can zoom in/out.
private function zoomControls():Void {
var test:Float = FlxG.camera.zoom;
var change:Float = 0.0;
if (FlxG.mouse.wheel > 0.0) {
change += 0.2;
} else if (FlxG.mouse.wheel < 0.0) {
change -= 0.2;
}
if (test > 1.2 && test < 3.0) {
FlxG.camera.zoom += change;
} else if (test < 1.2) {
if (change > 0.0) {
FlxG.camera.zoom += change;
}
} else if (test < 3.2) {
if (change < 0.0) {
FlxG.camera.zoom += change;
}
}
trace(test);
}
This works fine but as far as I'm concerned shouldn't. I set the initial zoom to 2.0 and I want the range to be 1.0 - 3.0. This does exactly only if I set the zoom to something in between [1.2 , 3.0]. But when I zoom out eventually it should hit 1.2 and never go below that but it does go to 1.0, which is what I want but that shouldn't happen. Not so similarly, if I get to 3.0 it doesn't go past 3.0.
When I first set this up I was doing it slightly different and depending on the platform, Flash, I would get some weird floats that weren't exact. So I set the numbers to more exact values but that doesn't seem to matter as far as Flash is concerned which will still come up with not exact floating points sometimes. I can't tell on the other platforms because no matter how I print it, trace/cpp.Lib, it is printing the right value but will evaluate to false if I print it as a bool vs the value that it's saying it is.
This was tested on 64 bit Ubuntu/Windows/OSX/Flash. I'm using Haxe 3.1.0-rc.4 and HaxeFlixel 3.2.2. Even if I set a return before the test if statements, and before that just adjust the zoom based off of change, it doesn't work. I've been testing this for about 2 hours which is way more time than I think I should be spending on something as trivial as this so I decided to post here.
Anyway, what exactly is going on behind the scenes here that are making these statements act strangely? I'm almost positive it has to do with the way floating points work but how can I get the behavior I expect?