HaxeFlixel/flixel-addons

FlxZoomCamera black borders issue and solution

Tembac opened this issue · 9 comments

  • Flixel version: 4.2.0
  • addons version: 2.2.0
  • OpenFL version: 3.6.1
  • Lime version: 2.9.1
  • Affected targets: All

Hi everyone,

I'm not using dev flixel so it is complicated to submit a PR. I found an issue with the FlxZoomCamera and an easy solution.

This is the file to test it:
https://dl.dropboxusercontent.com/u/24695185/camTest.rar

Q and W changes the zoom level. The issue is that if zoom is larger than 1 a black border appears on the corners.

Zoom 1:
http://puu.sh/t8qBc/1b77a604fe.png

Zoom 2:
http://puu.sh/t8qBN/0a68e41a3d.png

Zoom 2 expected:
http://puu.sh/t8qDd/971b59b4b8.png

The solution is to remove the align camera code from FlxZoomCamera. I think that code is really old.

Happy new Year!

Are you sure just removing all that code is the correct fix? FlxZoomCamera would be basically empty after that. :D

It works on my game. :D Did you try the test I uploaded?

My theory is that this was a kind of hack because the camera aligment was broken but now the camera works better than before and this code is older than the camera fixes.

the only thing that is useful from this class is:

zoom += (targetZoom - zoom) / 2 * elapsed * zoomSpeed;

Maybe it can be better if this is integrated to FlxCamera?

I did try it, but it seems like zooming in is smoother with the aligning.. Or is that just me?

With alignCamera() commented out, the sprite has this weird "jump" when zooming in.

I see the jump on both cases but with align it also adds a black bar on the left corner.
I'm using flixel 4.2.0 and not dev. Maybe dev changed something of the camera that fixed the black bar?

Hm... You don't think it's worse in the no-align case..?

I've probably been looking at this too much, can't tell anymore. :D

Maybe a little but the black bars are worse on my game because sometimes they cover a lot of screen.

Seeing as FlxCamera has improved a lot with zooming, it seems to me that FlxZoomCamera might not be worth keeping at all. Does it do anything more than a lerp to a target zoom?

@JoeCreates prevents a breaking change 😜

@MSGhero Sure, although breaking changes have to happen some time. :)

I prefer tweens to the lerping anyway due to the extra control and have personally never had any use for FlxZoomCamera. I added the bounds correction when targeting something to FlxCamera, which I think was the main use remaining for FlxZoomCamera, and the lerping is such a small thing it seems silly to keep a subclass for something so small. (Although I think inheritance to add behaviour is still fundamentally flawed, and composition should be favoured.)

To keep the lerping for those who want something simple, one suggestion would be to move the behaviour to FlxCamera for the lerping. Even better make a general target lerping component, perhaps with a macro to avoid reflection, that can be attached to any property of anything, then deprecate FlxZoomCamera to be removed in the next major version.

I'll probably make this anyway.

// Can be added pretty much anywhere, to the state or to a FlxCamera subclass
var targetZoom:TargetLerper;

override public function create():Void {
    super.create();
    targetZoom = TargetLerper.create(FlxCamera.zoom, 25); // property, speed
    targetZoom.set(2); // Zoom to 2x
}

override public function update(dt:Float):Void {
    super.update(dt);
    targetZoom.update(dt);
}