Gaming Your Way

May contain nuts.

HaXe, NME and I

Start of the week I had a play with HaXe / NME, I figured it was more than worth a day or two to play with them.

It was a mixed bag to be honest. I use FDT as I'm a Mac boy ( Plus I just like Eclipse, I don't understand the hate for it ), and they've really improved HaXe integration in it, but, HaXe and NME are different beasts, and the support for NME isn't as good. I did find a handy ant script for it, but... it may sound petty but it's a bit of a workflow breaker. Not a huge deal having to run an ant script, and I'm sure there would be someway to add it to the launcher chain which someone smarter than me could figure out, but screwing with my workflow really bugs me, and these simple little changes soon become an annoying chore. I don't want development to have more steps than it had before, that's the opposite of progress.

I'd read mono-develop was good with NME, and as Unity uses that and I'm looking ahead slightly, I thought I'd give that a go. Sometimes its better to start afresh rather than shoe horn things into your current setup. It's, well, it's ok but it's no FDT. I was missing auto-importing and code completion seemed to be lacking ( Again this could be a learning curve thing, I'm sure some people will read this and be screaming that I'm a dumb arse, it's just a simple key combo of <whatever> ).

So I set about porting O2, I mean it's just Float rather than Number, Int / int and Void / void pretty much. Got as far as my Init class where I call my fpsCounter and arse, first brick wall hit. From what I can tell you can't really included a code laden swc if you're using NME. Time to convert the code over to HaXe, which didn't take too long as there's virtually no code in the fps counter. K, job done, how do I include the assets I need ?

I had it in my head that HaXe supported importing swc's directly now, but the only info I could find was for importing swf's. Being the stubborn dick that I am, and stupidly believing my brain, I lost a load of time trying to find how to import a swc. You can't. K then, lets just import the swf. That was a bit of a struggle as I got my head around it, but at the end of day 1 I had NME set up, mono-develop installed, and 3 classes up and running with a fps counter. Oh.

Day 2 I started adding my Layers class, which required some assets from my huge assets.swc ( swf now ). It seems imported assets have to start with a capital letter ( Something I'd discovered doing the fps counter ), argh, I'm a camel case boy, every single asset export name in every game I've ever done is lower case. It's ok, it's fine, this will pay off when I'm running O2 on mobile at 60fps without stage3D. And now it's saying under mono-develop that it all compiles fine without errors, but there's no swf to run. What now ? ( Also before that I'd seen that my simple little 3k outputted swf was 24k when built with NME, there were some additional classes being shoved in there, but that's not a worry, shit it's only day 2, there's going to be things I don't understand and the community is really lively around NME so nothing to really worry about there )

At this point my spirit was starting to break. I wasn't liking mono-develop, the swf was taking nearly as long to compile as the full blown game using the Flex compiler just by adding the assets in there, and there wasn't a swf to test even at the end of it.

Fuck this. Time to go back to FDT and HaXe, let's get that working, then look at NME after. Ah, FDT I missed you, so much quicker and the build times are stupidly fast. Copied everything back over into the HaXe project and then this line gave me an error,

mapPlayField=new BitmapData((640/32)*7,(640/32)*6,false,0);

Really ? It seems using a division in HaXe casts the number as a Float, but the BitmapData constructor expects an int, which quite rightly threw an error. It makes sense, it's logical, I get it. It needs casting as an Int. But that was the exact moment this camel's back broke. I could either plough on for the rest of the week porting O2 to HaXe, and then hope that runs out of the box with NME, with the performance improvements I'd expect, or call it a day. You can guess which option won.

If this seems critical of haXe / NME, it's not meant to be. They're both as sexy as you like, it's more a combination of things. Losing my workflow, a lack of patience, and just the vast scope of porting a project as huge as O2. I've got an upcoming client project which targets Android ( I may be an indie, but an indie who needs to afford food ) and I'm going to use NME for that, it's a perfect way to test it and I'm glad I've done this ground work, it wasn't two wasted days, but when it comes to porting a large existing project I think it's not feasible until you've got a lot more experience of working with it under your belt.


PS. Thanks to all the guys who helped me via Twitter, wow, Team HaXe / NME are like Amiga owners in their love of the platform.