Skip to content

Instantly share code, notes, and snippets.

@AustinEast
Last active May 6, 2024 15:07
Show Gist options
  • Save AustinEast/108ec6601cf47389fdee81e0014cdc2a to your computer and use it in GitHub Desktop.
Save AustinEast/108ec6601cf47389fdee81e0014cdc2a to your computer and use it in GitHub Desktop.
Pixel perfect rendering with HaxeFlixel on desktop targets

To get Haxeflixel to maintain 1:1 pixel rendering at any scale for desktop targets:

In your Project.xml, add a new window property with an desktop conditional, resizable set to false, and the desired width/height to match the resolution you'd like to maintain.

<window if="desktop" resizable="false" width="320" height="180" />

Apply a shader to the FlxGame instance or the main FlxCamera instance as a filter. The base FlxShader can even just be used if the project doesn't require custom shaders.

FlxG.game.setFilters([new ShaderFilter(new FlxShader())]);

This is enough to make the game render at the correct resolution, but the game's image will be blurry thanks to Openfl's image smoothing. This can be turn off by setting the stage quality to LOW.

FlxG.game.stage.quality = StageQuality.LOW;

From this point the game can have its window resized/switched to fullscreen like so:

// Sets the window size to 960x540
FlxG.resizeWindow(960, 540);
// Sets the window to fullscreen
FlxG.fullscreen = true;

An example of this technique can be found here.

@poisonHornGames
Copy link

doesn't seem to work anymore :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment