HaxeFlixel Tutorial – Enabling Debugger

If you’re unaware, HaxeFlixel has an amazing debugging UI.

debug-ss

However, it’s not clearly explained in the official cheat sheet‘s “Debugging” section. Heck, if you tried searching for clues on Google, it would have took first timers (like myself) a while to figure out how to enable it.

What’s the problem? According to the cheat sheet, you can easily enable the debugger by adding this line of code:

It wasn’t mentioned where to use it, so let me give you a quick answer: you can usually write it in the create()  function in any of your State classes, e.g. in the MenuState.hx file.

But if you’re like me, you probably encountered another problem. When you build the game using lime test neko , the debugger won’t appear, even when you press the “~” (tilde) key. Why?

The answer is in your “project.xml” file. Scroll to the bottom and note the following line:

It basically means, the debugger won’t appear unless you’re in debug mode. It took me a while to realise this — lime test neko  is NOT a debug build. It’s the release build.

You could remove the line of code above and the debugger will work, but the reason it’s there is so that we can build release/debug versions easily without modifying the code.

In order to build in debug mode, you have to add -debug  to it, like this:

And now when you build the game, it will have the debugger! If it doesn’t appear, try pressing the “~” key.

Note! Some of the variables in FlxObject are only usable in debug mode, such as debugBoundingBoxColor  (API). If you get errors telling you that a debug variable does not exist in even though the API says it’s available, you probably have to use the -debug  when building.

One neat thing about it is the ability to show the hitbox of your game objects. You can add the following code in the create() function of your State class:

And now you know how to enable the debugger. As for how to use the debugger … I’m afraid I’m still learning, so I can’t teach anything yet. 🙂