Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust rendered DisplayObjects' dimensions with filters #2700

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

NexIsDumb
Copy link

@NexIsDumb NexIsDumb commented Mar 19, 2024

This is has been an old bug;
For example if you put one or more filters on a Flixel's FlxCamera (that for rendering Shaders, and so Filters, uses an OpenFL's Sprite) on certain screens you can easily notice that the camera gains +1 pixel on the right and bottom side (and so it's oblivious that this doesn't happen on FlxCameras only but on every OpenFL's Rendered DisplayObjects).
Me and @NeeEoo found an easy way to fix this on certain resolutions which comprehends a lot of screen sizes actually (still testing on FlxCameras), but we feel like there could be a more dynamic fix so this is going to stay a draft until we find out a better fix.
Here's an example of two overlapped cameras with the bottom one using filters (filters on that camera'a OpenFL Sprite) and the top one not using them but having a black sprite that uses the camera's dimensions (better visible on larger screens or zooming):
Screenshot_20240319-135118_Gallery
As you can see the bottom camera with filters has one more pixel on bottom and right side than the one without filters.
This disappears with this Pull Request's fix.

Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
@joshtynjala
Copy link
Member

Here's an example of two overlapped cameras with the bottom one using filters

Please post the code for this example. Thanks!

@NexIsDumb
Copy link
Author

NexIsDumb commented Mar 19, 2024

Here's an example of two overlapped cameras with the bottom one using filters

Please post the code for this example. Thanks!

Sure thing, here's WITHOUT the fix (the original code was tested on CodenameEngine, so sorry for the delay I had to rewrite it so you would be able to use it) (Also one last reminder: I'm using FlxCamera since for filters it uses an OpenFL normal Sprite):

package;

import flixel.FlxCamera;
import flixel.FlxG;
import flixel.FlxGame;
import flixel.FlxState;
import flixel.system.FlxAssets.FlxShader;
import openfl.display.Sprite;
import openfl.filters.ShaderFilter;

class Main extends Sprite
{
    public function new()
    {
        super();
        addChild(new FlxGame(1280, 720, PlayState));
    }
}

class PlayState extends FlxState
{
    override public function create()
    {
        super.create();

        FlxG.camera.bgColor = 0xFF0000FF;
        FlxG.camera.filters = [new ShaderFilter(new FlxShader())];

        var cam2:FlxCamera = new FlxCamera();
        cam2.bgColor = 0xFFFF0000;
        FlxG.cameras.add(cam2, false);
    }
}

And this is what I noticed when resizing to big window mode:
image

If instead I include this Pull Request's fix that +1 pixel is gone.

@NexIsDumb
Copy link
Author

Oops, had to edit, attached the wrong image

@joshtynjala
Copy link
Member

Thanks!

Rounding for defect to eliminate the problem completely
Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
@NexIsDumb
Copy link
Author

NexIsDumb commented Mar 19, 2024

With this the problem shouldn't be happening again because it's going to round for defect

@NexIsDumb NexIsDumb marked this pull request as ready for review March 19, 2024 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants