Skip to content

Flixel 5.0.0 Migration guide

George Kurelic edited this page Apr 13, 2023 · 23 revisions

Flixel 5.0.0 is the first major update to flixel since 2016. Since then, we've added many new features without messing up existing games but if you want to make a great game engine, you need to make a few breaking changes. In order to keep major version updates to a minimum, we ended up stock-piling a large list of fixes and features. This guide will help you utilize them in your existing Flixel 4 games.

How to Migrate

  1. If your project is using an older version than 4.11, it might be a good idea to try 4.11 before grabbing the latest haxelib
  2. Be sure to check out the changelog for a quick overview of every change that was made

New Default Save Location #2566

The old default args for FlxG.save.bind were ("flixel", null) where null would be replaced with the full url or file path to the application. This created issues where releasing updates could create a new save path. The new args are generated from your Project.xml's file and company metadata, respectively. Game's will automatically look for the legacy save file, and migrate the data over to the new save if it exists.

You can also specify your own desired save path for FlxG.save, just call FlxG.save.bind("mySaveName", "mySavePath"); before instantiating your FlxGame and it will be used by flixel, internally, to save and load sound, window and debug preferences. Previously the default save would overwrite this value when the FlxGame is initialized

Collisions Preserve Momentum #2422

Collisions with FlxG.collide between objects of different masses used to flip out and act strangely, this is now corrected. This is still a breaking change, however, and anyone depending on the old system should be aware. For instance, any game using FlxReplay to replay player runs with collisions using objects of different mass or elasticity will have invalid replays on the new system. To keep the Flixel 4.0 collision physics on a Flixel 5.0 game you can use the compiler constant FLX_4_LEGACY_COLLISION.

Angles at 0˚ Point Right, Not Up #2482

There used to be some inconsistencies regarding angles, almost every math utility would point right at 0 degrees, but not everywhere. Notably FlxSwipe and FlxPath treated 0 degrees as up. If you're using a FlxPath on a sprite with autoRotate enabled, you'll need to change your sprite to face right at 0 degrees. (actually wait, I should make an offset property to solve this more easily)

FlxVector is Dead, All Hail FlxPoint #2557

It seemed silly to have 2 separate 2d position classes, so we took every method in FlxVector and moved them all to FlxPoint. FlxVector Still exists, but it's been reduced to a deprecated typedef of FlxPoint. Not many devs knew FlxVector existed, so hopefully this will expose more devs to cool features like length and degrees getter/setters, or math helpers like dotProduct and bounceWithFriction.

As a bonus, we've also added math operators, like +, +=, -, -=, * and *=.

AssetPaths has less caveats #2575

AssetPaths (or any class built using FlxAssets.buildFileReferences) will no longer throw an error when two files have the same file name. Now it will give a warning and ignore whichever file is nested more deeply in the folder, or whichever file was found later.

The filterExtensions arg was removed and replaced with include and exclude args. These new args can either be an EReg, or a wildcard string, similar to openfl's project.xml args. For example to exclude everything in a folder called "test", as well as any .ase files, you would either use "*/test/*|*.ase" or ~/\/test\/|\.ase/.

Lastly, the rename arg was changed, significantly. Custom renaming is already a relatively new and unknown feature of AssetPaths, but now it may be the most powerful! The rename arg is a function that will take a filepath (a relative filepath from the project.xml) and returns a field name used to access that path. The previous versions there would be no way to include two files with the same name, for instance, "assets/images/mario/walk.png" and "assets/images/luigi/walk.png" wouldn't be allowed, now you can call them mario_walk.png and luigi_walk.png. Additionally, you can return null to exclude a specific file.

FlxAxes is now an enum abstract

A simple change, but could impact your projects, in addition to adding a NONE value, FlxAxes is now an Int abstract that uses bit flags.

var X    = 0x01;
var Y    = 0x10;
var XY   = 0x11;
var NONE = 0x00;

This means you can't use of the match method anymore, but checks like if (axes.match(X | XY)) can be replaced with if (axes.x).

Zoom arg removed from FlxGame Constructor (#2591)

If you would like your game to have a large pixel size, simply set width and height to a fraction of your window size, defined by your Project.xml. for instance, in 4.11 if your FlxGame constructor was:

new FlxGame(
    stage.stageWidth  / 2, // width
    stage.stageHeight / 2, // height
    MenuState,             // initial state
    2,                     // zoom
    60,                    // update framerate
    60                     // draw framerate
);

Just remove the zoom property, like so:

new FlxGame(
    stage.stageWidth  / 2, // width
    stage.stageHeight / 2, // height
    MenuState,             // initial state
    60,                    // update framerate
    60                     // draw framerate
);

FlxMouseEventManager is now an instance, not a static manager #2540

Rather than having a single, static manager for globally managed mouse events, now you can have multiple instances, just like FlxTweenManager or FlxTimerManager. We also added a FlxMouseEvent class with static methods that will call the corresponding methods on the default manager.

You can see how the FlxMouseEventManager demo was migrated, here. In short replace static calls like FlxMouseEventManager.add(...) with calls to FlxMouseEvent.add(...).