Uncategorized

A Foray Into Haxe

When I look back on the various things I’ve written over time, I can see that a person might get the idea that I’m like Jeremy the Crow from the Secret of NIMH.  (I’ll give you bonus points if you get that reference without having to research it.)

Today, I started evaluating Haxe for use as a development environment for games.

First, a word about Haxe.  It will make applications for multiple “platforms” (I know that some folks object to the word platform in this sense.  I also don’t care what some folks object to.), which include JavaScript, Flash, Neko, and PHP.  I had to look Neko up, decided I didn’t care about it today, and looked at Javascript and Flash.

I discovered that while Haxe can be used to target these several types of output, the idea that you will write code a single time and simply switch what you are compiling it for is a laughable pipe dream.  It uses different APIs based on your output, so if you make something that targets flash, you won’t be able to compile it for javascript, and so on.

Not to say that you couldn’t write the core of the game without either API, and then writen the rendering code specific to the platform, but that’s the same no matter what multi-platform language you are using.

For flash output, Haxe takes care of the code part. The image resource portion (which is paramount in the game of HamQuest) has to be stored in a separate resource swf that the haxe compiler can bring in and use.  Fortunately, swfmill exists and is pretty simple to use for a quick little resource swf.

I built the quick “Hello World” app. Worked.

I built the quick “Draw a Rectangle” app.  Worked.

I built a quick “Show an image loaded from a resource swf”. Worked.

The only thing I have left to do is ensure that I can get keyboard input, but based on what I have seen as examples elsewhere on the web, it looks like I can do it just fine, but I’m not going to assume anything prior to getting really started.

As far as the Haxe language itself: its yet another CBL (curly brace language), and reminds me of every other CBL I’ve used.  Seriously, the various features of the language reminded me of features in other languages, joined together into this mongrel language.  I can easily see the influence of Java, JavaScript, ActionScript, C#, C++, and C.

Additionally, there are a couple of weird wrinkles Haxe has of its own (or at least, I haven’t seen these exact language features anywhere else).

First, the “for” loop isn’t the normal structure of “for(index=0;index<10;++index)”, and instead looks like “for(index in 0…9)”, and additionally has iterator objects that can be used in place of the 0…9 construct.  Basically, this is similar to the JavaScript “for(var i in obj)” construct, and basically means all “for” statements are really “foreach” statements, which I can deal with.

Second, the enums are kind of weird, but in a way that is potentially very powerful.  Time will tell if and when I make use of their flexibility.

Thirdly, in addition to being able to make instant objects “var obj={“x”:10,”y”:20};” as in JavaScript, there is an extension to this that allows a shorthand kind of inheritance.

So my initial impression is: Haxe is a mongrel CBL (which isn’t a bad thing) with a “funny” for, and a few quirky features I’m likely not to use, at least not initially.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s