Start a hosting plan from $3.92/mo and get a free year on Tuts+ (normally $180)
Haxe (pronounced "Hex"), is an open source, multi-platform language, capable of compiling to various languages, targeting Windows, Flash Player, WebOS, Android, Blackberry, and HTML5 (in beta at time of writing). NME, which goes hand in hand with Haxe, is the library that allows for this amazing cross-platform action.
While this article is geared towards those with programming and game development experience, it does supply the tools and resources needed for someone with little or no experience to get started with Haxe as their first language. In this article I'll tell you why should use Haxe, help you get Haxe and NME up and running on your machine, point you to some of the best learning material out there, and help you get your foot in the door with the Haxe community.
Why Use Haxe and NME?
If you're involved with programming or game development, or perhaps even just spend a significant amount of time on the internet, you've heard the phrase "Flash is dying". I'm not going to waste anyone's time with that debate right now, but the idea is related to my next thought. As a game developer, specifically one who has only made money through Flash games thus far, this phrase was moderately concerning to me.
I'll state now that I'm not convinced Flash is dead, or going to be dead any time soon, but I still wanted a backup plan. I have now found an answer to my worries: Haxe.
I've always wanted to work with other platforms besides Flash, but the amount of work required to switch has always seemed too large to justify or to tackle; Haxe changes all of this. As a language, Haxe is almost identical to the AS3 code I've been writing for years. Even better, FlashDevelop (my editor of choice for Flash games) has amazing support for Haxe, so I don't even need to familiarize myself with a new IDE. Not only does Haxe give me the security of not relying on Flash any more, it also allows me to target new platforms.
In the past, targeting multiple platforms has always been an enormous pain, to the point where I usually pretend the option doesn't exist. You either have to port your code to a new language (one you may or may not know already know), or shop around for someone who is tried and proven to do it for you. I've sold mobile rights to one of my games before, but even after an upfront payment to me, the game never went live.
With Haxe, you can export to various platforms by simply changing a drop-down box, and adding a tiny bit of conditional code to detect the platform and change settings such as full screen mode. That's not to say you won't occasionally have to work out a few kinks, but from I've read, and the little experience I do have, said kinks are hardly worth mentioning.
Setting Up Haxe and NME
The most important thing you'll need to do first is get your computer set up ready to use Haxe and NME.
Getting Haxe and NME up and running can be a bit confusing, but I've written a comprehensive guide on my website to walk you through step by step. Go ahead and follow my getting started with Haxe, NME, and FlashDevelop guide now, and head back over once you're up and running. Note that my guide uses FlashDevelop, and while I highly suggest this IDE, there are others, so feel free to experiment.
Mac or Linux
If you're not running a Windows machine, I unfortunately don't have a comprehensive step by step guide. That being said, Haxe is compatible with both platforms, and you can find the installers and basic instructions on the Haxe download page. If you run into any specific problems, I suggest skimming over my Windows Haxe guide, as it may shed some light on what went wrong. If that doesn't work, skip ahead to the "Join the Community" section, and contact Haxe through Twitter or email for further support.
Know Your Basics
Once you've got your work environment set up, you'll want to familiarize yourself with the basic syntax of Haxe. I highly suggest you do this by reading the Haxe Syntax Reference.
If you're feeling more comfortable with the basic syntax of Haxe, you're now a sponge, waiting to soak up all the knowledge Haxe has to offer. At this point, I suggest skimming the entire Haxe reference page, and reading anything and everything that stands out to you. The Haxe support team has done an amazing job building their reference material, and anyone starting out should make great use of it.
Go Ahead, Port Something!
Whether you're coming from AS3, Java, or some other language, porting to Haxe is pretty easy. Since Haxe supports nearly all features any mainstream language uses, you're generally just stuck with some tedious syntax changes. That being said, any modern IDE supports find-and-replace (with FlashDevelop supporting "Find and Replace In Files", targeting every file in your project), and with a bit of patience, you can have your project ported in no time.
If you have any projects you feel could be ported, I highly suggest doing so, as the experience you'll gain learning the new syntax and error codes is extremely valuable. Once you've ported the game over, you can even go ahead and get your game to run on other platforms through the power of NME - a very nice reward for all of your hard work. At this point, you could then submit your older projects to new platforms, and potentially earn some revenue you never saw coming.
Libraries Are Your Friend
If you're anything like me, you absolutely love libraries. While I'm perfectly capable of creating a game from scratch, I'd much rather use a tried and tested, feature-complete library. Due to the ease of porting, the growing community, and the overall awesomeness of Haxe, there are quite a few libraries that help get the job done.
Haxe comes with the amazing hHaxelib Haxe package manager, which keeps track of all available libraries submitted to the manager. This allows you to search for libraries from one convenient location, and even update all installed libraries on your computer to their latest version, using the
haxelib upgrade command within the command prompt.
When a new library is downloaded and installed you'll need to make sure your project includes the classpath of that library. As explained in my getting started article, all Haxe projects contain an
application.nmml file. In this file, there is a small section of code for classpaths and haxe libs. If we downloaded the HaxePunk library, and wanted to include it in our project, we'd simply add the following to our
<haxelib name="haxepunk" />
This let's our project know that we're using the HaxePunk library, which the Haxelib Haxe package manager controls. NME is also a library controlled through Haxelib, which is why you'll see the following in any Haxe NME project created with FlashDevelop.
<haxelib name="nme" />
Just as before, this lets our project know that we're using the NME library, which is also managed through haxelib. While you can manually define a class path for a library, most major libraries are supported through haxelib, and the system is significantly more organized.
A Few Popular Libraries
- HaxePunk - A port of the popular flash library FlashPunk. While it was originally a port, it's now growing to support optimized performance, especially among the various supported platforms.
- Haxe Flixel: A direct port of the popular Flash library Flixel.
- Nape: An absolutely amazing 2D physics engine that holds it own even against the popular Box2D.
- Kong.hx: A strongly typed, direct port of the Kongregate API.
- NME Tiled: A library that gives support to the popular tile based editor, Tiled.
Join the Community
Haxe has a new, yet thriving community. While Haxe is still young, it's rapidly growing in popularity. Upon joining Haxe, it almost seemed like I was jumping on the bandwagon, because everywhere I looked, more and more people I knew were talking about Haxe; this was pure coincidence of course, but it just goes to show that Haxe is on the rise.
The community members I have interacted with thus far are great. Matt Tuttle does a great job managing HaxePunk on GitHub, the Haxe twitter accounts are always quick to respond to tweets, and I've seen more and more quality Haxe-related blog posts lately. I strongly urge you to get active in the community, as this has been the absolute best way for me to get help, and help others, with this amazing language.
Tweet It Up
Haxe has a number of Twitter accounts that are decently active, and more and more developers join the community every day. Below are two official accounts which I strongly suggest you follow if you want to stay in the Haxe Twitter loop. Feel free to tweet them any and all questions you may have, as they're very quick to respond, and have always been helpful to me.
Haxe Google Group
The Haxe Google group appears to be one of the most active locations on the net for asking a Haxe-related question, and getting a quick answer. If you prefer forums over a Twitter response, join this group.
Your Future Awaits...
Now that you're equipped with the ability to program using Haxe and NME, there are endless opportunities for you as a game developer. With this one powerful language, you can now push your projects across a growing number of supported platforms. Your bank account will grow, your reputation will flourish, and you'll do it all with less effort than ever before.
I hope you've learned a great deal about Haxe through this article, and on behalf of the entire Haxe community, I look forward to seeing you help this amazing community and language grow.