Thursday, August 30, 2012

Installing and Setting Up HaxeFlixel on Windows

HaxeFlixel is a Flixel port for Haxe the "universal" programming language and the NME application framework to support applications on iOS, Android, webOS, BlackBerry, Windows, Mac, Linux and Flash Player without requiring code changes for each target; Flixel is a popular library for developing 2D Flash games. This tutorial will teach you how to install Haxe, NME, HaxeFlixel, their dependencies, and try out one of the HaxeFlixel demos using Flash.

Step 1: Install Haxe and NME

Download the installer for Haxe and NME from the NME website and install it; I'm using the NME 3.4.2 installer, and I've changed my installation location to C:\HaxeNME.

Step 2: Install HaxeFlixel

Open up a Command Prompt, on Windows 7 this is located in Start, then Accessories, then Command Prompt. Type in the following command to install HaxeFlixel, hit Enter after typing it in:

haxelib install flixel 

Don't close the Command Prompt, you'll need it for the next step.

Step 3: Testing Installation

The developer of HaxeFlixel has also ported many of the demos from Flixel to HaxelFlixel, and they are available on GitHub. Click on the ZIP button to download the demos as a .zip file to your computer and unzip that archive. Next, you'll need to navigate to that directory in the Command Prompt. For the sake of simplicity, I've unzipped the demos and placed them on my C:\ drive in a folder HaxeFlixelDemos, so that the C:\HaxeFlixelDemos folder contains the 20 or so demos. To navigate to this directory, type the following command into the Command Prompt where "cd" stands for "change directory":

cd C:\HaxeFlixelDemos

but let's say you've put your files somewhere else like your Dropbox folder on Windows 7. You can navigate to that directory using the following command where [[USER]] is your computer username:

cd "C:\Users\[[USER]]\Documents\My Dropbox\HaxeFlixelDemos"

This link has more information about navigating Windows using the Command Prompt.

Staying with the C:\HaxeFlixelDemos location, the next step is to choose the demo you want to try. Let's try FlxInvaders to change to that directory type in:

cd FlxInvaders

You can see what files exist in the directory by typing in the command "dir". You'll see an .nmml file, that is the file that contains the instructions for compiling/packaging the demo. To test out the demo, type in the following command:

nme test FlixelNME.nmml flash

And the Flash version of the game should pop up. Enjoy.

As far as actually coding a game using HaxeFlixel, your two main sources of information for functions available will be the Flixel API and the Haxe Language Reference. The Flixel forums are also a lot of help, you'll just need to interpret any comments to the Haxe language, but for the most part it is very similar to Actionscript used by Flixel.

No comments: