Setting up a HaxePunk Project

Some notes about setting up and using HaxePunk

up

2013-03-02

Edit (2013-03-06): updated title to reflect the post a little better

Setting up the development environment

  1. Setup the editor or IDE, I use vim, so install vaxe
  2. Go to www.nme.io/download/ and follow the instructions
  3. Install HaxePunk: haxelib install HaxePunk

Setting up the project

  1. Create the project skeleton: haxelib run HaxePunk new [project name], replacing [project name] with the name of the folder to use for the project
  2. Edit project.nmml with your project specific details
  3. Add src/worlds folder to hold your world source files
  4. Add src/entities folder to hold your entity source files

Add some code to make a useable, but very basic HaxePunk project

Add this code to src/worlds/Game.hx, it can be used as a very basic jumping off point:

#!haxe
package worlds;

import com.haxepunk.World;


class Game extends World {

    public function new() {
        super();
    }

}

Then set HaxePunk to use that world as the active world by adding the following to the end of the init function in the Main class (src/Main.hx):

#!haxe
HXP.world = new worlds.Game();

Building the project

I like using neko to do a lot of my testing and development. It has faster build times than for cpp, and I don’t have to deal with flash (personal preference).

#!bash
$ nme test project.nmml neko

The ‘test’ argument just tells nme to update (copy assets) and build the project, then to run what was built right away. You can do lots of other things with nme, see the nme documentation, or the command line help:

#!bash
$ nme help

End thoughts

Nothing fancy, but it gets the project up and running. It should be noted that a lot of FlashPunk documentation and tutorials are useful when trying to learn HaxePunk – they usually don’t match perfectly, but the class and method names are mostly the same and available in both, so it’s easy to pickup things in snippets.