HaxeFlixel / flixel

Free, cross-platform 2D game engine powered by Haxe and OpenFL
https://haxeflixel.com/
MIT License
1.97k stars 434 forks source link

Fullscreen toggle unreliable? (MacOS) #3089

Open increpare opened 6 months ago

increpare commented 6 months ago

Code snippet reproducing the issue:


import flixel.FlxG;
import flixel.FlxState;

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

    var fullscreen_cached:Bool = false;

    override public function update(elapsed:Float)
    {
        super.update(elapsed);
        // trace elapsed
        FlxG.watch.addQuick("FlxG.fullscreen", FlxG.fullscreen);
        // FlxG.watch.addQuick("displaystate", stage.displayState);
        if (FlxG.keys.justPressed.F)
        {
            FlxG.fullscreen = !FlxG.fullscreen;
        }
        if (FlxG.keys.justPressed.G)
        {
            FlxG.stage.window.fullscreen = !FlxG.stage.window.fullscreen;
        }
        if (FlxG.keys.justPressed.H)
        {
            fullscreen_cached = !fullscreen_cached;
            FlxG.stage.window.fullscreen = fullscreen_cached;
        }
    }
}

Observed behavior: The game starts windowed mode (either neko or CPP builds have it). Optional: Press F2 to open debug window to see FlxG.fullscreen in the watch panel. 1: Press F to toggle to fullscreen 2: Press F again. Note in the debug window that FlxG.fullscreen is now false, even though the game remains in windowed mode. 3: Press F again. FlxG.fullscreen is now true, and the game remains in fullscreen. 4: Press F again. This time it switches to windowed mode, and in the debugger, FlxG.fullscreen is now negative (you can keep pressing F and the behaviour loops)

Expected behavior: I expect step 2 to bring me back to windowed mode.

Also note, pressing G to assign FlxG.state.window.fullscreen also has errors, but you press it three times to go back to windowed rather than four. Caching the value yourself as in H works. (But doesn't keep track of the user manually maximising the window by pressing the button).

I guess I should see if Lime... has this behaviour as well. Indeed it does, though...slightly different behaviour - https://github.com/openfl/lime/issues/1771

Geokureli commented 6 months ago

Also note, pressing G to assign FlxG.state.window.fullscreen also has errors, but you press it three times to go back to windowed rather than four.

Sounds like lime's behavior matches this description, my initial guess is that flixel takes 4 presses because it's actually setting FlxG.fullscreen to true in step 3, while the game is already fullscreened. I think the crux of the issue lies with lime, but it's worth looking into as a possible flixel issue, either way I do think flixel needs some changes with how it handles fullscreen