I moved to a new URL! Check it out!

FlashDevelop with HaXe NME and HaXePunk

FlashDevelop with HaXe NME and HaXePunk
I spent most of yesterday diving into a whole new world of magic and fun: Haxe. I was hesitant at first because I was dreading the whole ordeal of setting up a new development environment, but it turned out to be way more straight forward than most set ups I've experienced.

I ended up getting a quick demo of thousands of entities rotating, scaling, and alpha blending at a steady 50-60fps with the Windows build of HaxePunk, and that has me pretty excited!

Image


Follow along as I take you on a journey of code and game development! (For reference, I'm using Windows 7.)

Before You Start


I'm assuming that you are a flash developer that's using FlashDevelop and you want to migrate to Haxe NME. More specifically, this will be about getting HaxePunk up and running as quickly and as easily as possible. Oh, and I'm also assuming you're using Windows.

Download NME Installer


Go on over to the NME downloads page and download the installer for your OS. For Windows, you want to download this installer.

The NME installer will take care of a lot of stuff for you, and actually we're already almost done after installing just this.

Command Line Setup


After the installer is finished running you'll have to do one more thing to actually finish the set up completely. Open up a command prompt window (if you go to the start menu and just type 'cmd' you'll find it) and type 'nme setup windows' into it.

Image


You'll be presented with a prompt to install Visual Studio C++ Express. Go ahead and do that, as this is necessary for FlashDevelop to build your project to a native windows application.

FlashDevelop Template


Now that NME is installed and the Windows stuff is set up, you'll want to install some FlashDevelop project templates. This enables you to start a new NME project in FlashDevelop when you launch it.

New NME Project


This is where things get a little weird since we're not following the typical HaxePunk install route. We're going to start a new NME project, and then dump HaxePunk into the source folder of that project to use it. There are other ways to do it, but after struggling with some stuff yesterday, this is the best way I could get working for now.

Image


Start a new project in FlashDevelop and choose an NME Project. Click OK to create the project. It generates some default files and folders for you, and we're going to mess with those a little bit now.

HaxePunk Setup


Almost done! Now go download the latest version of HaxePunk from the Git page. Just click on the "ZIP" button to download a zip file of the entire repository. Inside that zip file that you just downloaded there is a "src" folder. Inside that folder is a "com" folder. Take the "com" folder and add it to the "src" folder of the NME project we just created.

Image

You also need to take the contents of the "assets" folder in the HaxePunk zip file and place them in the "assets" folder of your new project.

Image

Hooking up Assets


There's one more important thing that you'll need to change, and that's the "application.nmml" file. For those of you that have worked in AIR, this is somewhat similar to the application.xml file for AIR projects. In the assets section (line 19) you'll need to add some lines for the HaxePunk assets we just added.

I used this file as a guide to figure out what to modify in here. My assets section of my application.nmml ends up looking like this.

A New Main.hx


The final thing that needs to be changed is the Main.hx file in the project. Since HaxePunk works differently than the native Flash style code, we'll need a new Main.hx. Here's the complete code for Main.hx that I based off of this file.

package ;

import com.haxepunk.Engine;
import com.haxepunk.HXP;

class Main extends Engine {
public function new() {
super(640, 480, 60, true);
}
override public function init():Dynamic {
super.init();
HXP.console.enable();
trace("HaxePunk is running!");
}
public static function main() { new Main(); }
}

Now with any luck you should be able to build this project into anything you want! Flash, Windows, HTML5, and more. I haven't done much with Android or iOS building yet, so I'm not really sure what's involved for those... but this should be enough to get you started with HaxePunk with NME.

Pro Tips


There's an option in FlashDevelop that makes autocomplete kinda clunky with Haxe for some reason. To fix this issue, go to Tools -> Project Settings. Go to the "HaxeContext" section, and set "Disable Completion on Demand" to False.

Image


If you have issues compiling to a Windows build, try setting up Visual Studio again with the command line "nme setup windows"

Check out this handy list of AS3 -> HaXe conversions.

Make sure you're using the nme library when importing classes. For example, you want to use "nme.geom.Point" for the Point class and NOT "browser.geom.Point" or any other. FlashDevelop will autocomplete for you alphabetically, so just double check that you're getting the nme versions of things when importing.

Downloads Recap


Download the latest HaxePunk zip.

Download the NME 3.5.5 Windows installer.

Download the verison 4.3.0 of FlashDevelop.

Download the FlashDevelop project templates for HaXe NME.

Comments

Feyfausto
Feyfausto
and a tutorial how can we conver a FlashPunk project for Haxepunk? :3
Posted April 8th 2013 2:00 PM
ratking
ratking
I guess the struggles you experienced are related to my own? See here: http://forum.haxepunk.com/index.php?topic=342.0
Posted April 11th 2013 12:47 PM
Kyle
Kyle
Actually strangely enough I didn't encounter that specific problem. I actually just wanted direct access to the HaxePunk source inside my project rather than having it live in the Haxelib folder in a faraway place.

I'm actually putting Haxepunk down for now because it has a lot of shortcomings that I didn't notice when I first started experimenting with it. It's a bummer because I'm really excited about the prospect of better performing games on Win/Mac/Linux, but it's just not polished enough for a big game project.
Posted April 12th 2013 1:39 AM
Makai
Makai
Are these shortcomings related to HaxePunk's base in FlashPunk or are they issues with HaxePunk itself?

Care to elaborate a bit more on this?
Posted April 29th 2013 3:35 PM
Kyle
Kyle
The short comings are with HaxePunk itself. I love FlashPunk and if I could use it forever, I would. HaxePunk is missing some of the core functionality of drawing (right now at least) that I use a lot in FlashPunk. Stuff like drawing lines, circles, rectangles, manipulating bitmapdata and using it for image rendering, and certain image features like sprite.flipped are broken or not yet implemented for native targets. I believe it's also not ported with the latest version of FlashPunk in mind (which is maintained by Draknek and not Chevy Ray anymore)

If there was a complete copy of FlashPunk as it stands right now with way better performance and compilation to native targets then I would be all over it. HaxePunk is close, but it's not there yet for my needs unfortunately.
Posted May 3rd 2013 3:45 PM
salaniojr
salaniojr
Hi Kyle,

I've been researching the avaiable options in Haxe and, as you pointed out, it seems that they lack some maturity. The one ahead is HaxeFlixel in community activity, commits and docs. It can be a good start.
Out of curiosity... are you still using Haxe? If you do, what are you going for? Creating your own framework?

Thanks
Posted September 30th 2013 9:05 AM
Kyle
Kyle
Hey! I am not working in Haxe anymore. I called it quits on Haxe after I realized that a lot of basic functionality that I was used to was not present yet in HaxePunk. I did look into HaxeFlixel a little bit, but after some more experimentation I landed on C# and SFML which I'm currently using to build a framework.
Posted September 30th 2013 3:35 PM
Andre
Andre
Are you able to provide the source code for the test app in the post? The one with a lot of rectangles
Posted February 9th 2014 3:31 PM
Kyle
Kyle
Unfortunately it's been a long time since I've used Haxe, and I don't have the source for that test application anymore.
Posted February 10th 2014 12:02 AM
Andre
Andre
Can you remember how you drew the squares and rotated them? Was it an HaxePunk API or AS3 directly?
Posted February 10th 2014 8:16 AM
Kyle
Kyle
I'm pretty sure I just made a square graphic and used HaxePunk to create thousands of them. When they were created they would get a random color and alpha and scale, and during their update they would rotate.
Posted February 10th 2014 12:00 PM
new comment!

Post your comment!

Name
Email
Comment