May 232012
 

So I swore I’d never touch Haxe ever on twitter recently. At least for a year or so. Why? Well, I’m too busy; Haxe isn’t quite mature enough for my tastes; support forums are kinda slim pickings and it’s hard to Google solutions to common problems. Mostly, though? I’m just scared of new things. I knew I should probably give it a try, and just decided not to.

A Wild Update Appears!

Well, early this morning a new version of FlashDevelop was released, with enhanced support for Haxe NME. I found myself in a fell mood, locked myself in with a livestream, and gave myself 1 hour to learn Haxe and make a game!

First up, some Q&A. These are questions I had that I didn’t really know the answers to until I dug into it, so I’ll share what I found with you:

What is HAXE?

 It’s a free programming language whose syntax is based on ECMAScript (similar to UnityScript, ActionScript 3, and Dart syntax). The project grew out of AS3, so it bears the most similarity to it. Here’s the official website and the wikipedia entry. I don’t recommend you download Haxe just yet, read on…

How do you pronounce it?

Wikipedia says it’s officially “hex,” but some jerks call it “hacks” and it’s starting to stick. I’m going to call it “hex” from now on!

What is NME?

It’s a free library collection for Haxe that closely emulates the Flash libraries we know and love – the DisplayList, Sprites, Bitmaps, Textfields, Points, Events… All those lovely things. The combination of Haxe and NME creates the most comfortable transitional environment for AS3 developers, though there are some big changes. See the official website here. The download for NME includes Haxe itself, along with a bunch of other requisite files, so I recommend grabbing this!

Why use Haxe NME?

The two biggest reasons to use Haxe NME are SPEED and OUTPUT TARGETS.

SPEED: Haxe NME consistently outperforms every single AS3 metric I’ve seen. Name a test. Any test. Haxe NME will outperform it. Adobe’s .SWF compilations, AIR compilations, and even AIR’s swf-to-native-bytecode iOS/android compilations introduced in AIR 3.1 can’t touch this magic. From iterating through arrays to displaying particle effects, Haxe is simply a better compiler.

OUTPUT TARGETS: Haxe NME can compile to just about anything, natively. iOS, Android, WebOS, BlackBery, Windows, Mac, Linux, HTML5, and good ol’ fashioned SWF. If you lose the NME library, you can even target PHP, C++, JavaScript, Java, Neko, and C#. This is the swiss-army-knife of development tools.

Another good reason to use it? It’s a more advanced/mature language than AS3, so some common annoyances have been addressed and many aspects of development are much easier.

What’s different between AS3 and Haxe syntax?

Take a look at this article right here, it’s pretty much my bible as an ActionScript developer. Check out the awesome upgrade to FOR loops in there. We even have (optional) automatic type inference in there, while maintaining strict typing! Less keystrokes with all the debugging magic. You should also read this whole blog, it’s great.

So what did I make?

I opened up FlashDevelop, and with no experience (and armed with only the basic knowledge above) I started hacking away at a Haxe project. LiveStream captured my hour-long effort, but an hour of me getting frustrated and looking at docs doesn’t make for good TV, so I didn’t paste it to youtube. If you really badly want to check it out, look in my Twitch.TV video archive. :P

With a lot of help from the studio audience (Pekuja in particular!), I managed to get a little game together: FACE CHASER! Play it now!

  • Your face is being chased down by an ANGRIER face!
  • The angry face has 3 hit points, which it loses as it bumps into the edge of your browser. You’ve got to play chicken with it!
  • When angry face dies, a FASTER angry face appears!
  • If angry face touches you, YOU DIE Spams the background!

You can check out a .ZIP of my complete FlashDevelop package here, if you want it. I wouldn’t. :3

So how was Haxe NME?

Intriguing. It’ll take a lot of practice to get coding in it quickly, and I’ll need to convert a lot of my library helper functions, but it’s overall pretty darn good.

I wouldn’t use Haxe NME for a commercially sensitive project right now. If something goes wrong, or you need a fancy binary plugin library or something, you might be out of luck. But if you keep things simple…

Well, let’s just say I’m going to try to use Haxe NME for all my future game jams. :) Maybe slowly over time I’ll get up the courage to use it for everything!

  3 Responses to “Haxe NME: Learn and build in 1 hour?”

Comments (3)
  1. I used NME a couple of years ago for a large social game. It was an isometric RPG that kind of looked like the original Diablo game, but set in a western/cowboy setting. I was the technical lead for the game, working under a CTO who was excited to deploy a game to Facebook, while also setting ourselves up for good performance on mobile.

    After he left, the CEO felt nervous, and cared nothing for mobile. When he asked me to convert the codebase to AS3, I was able to change the entire game in a single day. Of course, the game was compiling and running in Flash the entire time, but he felt nervous.

    One of the extra benefits of NME in my mind, compared to solutions like Corona, is that your code can compile for Flash, or package with AIR, without losing your codebase, or if you “need to” convert to AS3 it can be done in a few hours, since the languages are similar. What NME does do is open doors of opportunity. While Actionscript 3 only provides AIR as an opportunity for platforms, NME provides ways to create more deeply integrated extensions for each platform, or to access more platforms, or to reach better framerates or integrate more features for each platform. For example, NME has had gamepad support for the desktop since 3.3 was released. You don’t have to wait for Adobe.

    If you’re used to AS3, this “cheat sheet” should help:

    http://www.haxenme.org/developers/documentation/actionscript-developers/

  2. Intriguing! Several people have suggested HAXE to me as a way to get better performance on devices. My main fear is of course lack of community support since not a day goes by that I don’t look something up for AS3. It’s encouraging to hear that it’s relatively easy to convert from HAXE back to AS3, but I wonder how easy it is to go the other way around.

    Anyway, support for NME in FlashDevelop makes this a real possibility… At least for my next prototype.

  3. @joshua: Thanks for the link, I had it in the post but it’s so good it’s worth posting a second time. I have it bookmarked and almost always open. :)

    @sarah: converting as3->haxe is comparatively simple than, say, xcode, but it would still take a solid week to convert a full on game like rebuild, I’d think.

    There’s a bunch of little things you can automate, like void->Void and Boolean->Bool, but some things you can’t automate, such as … Haxe doesn’t allow you to assign values in a variable declaration. Moving all these into the constructor is fine normally, but suddenly things start breaking if the variable was Static, and now your re-assigning it on every constructor and oh jesus noooo

    The thing that bugs me the most about Haxe NME is indeed the level of support though. Like, JSON is a separate package, and Haxe has a package manager you can install, but there’s no download links to it and they only give installation support for Linux systems. still haven’t figured it out.

    It’s almost impossible to NOT google help for anything in AS3, on the other hand. total safety net there.

Sorry, the comment form is closed at this time.