NME Game Example: “Pirate Pig”

If you are familiar with webOS, you may have heard of Enyo, a Javascript framework which powers many of the built-in applications for the HP TouchPad. Recently, Enyo was released as open-source software, so you can use the framework on more platforms in addition to webOS, such as iOS, Android or BlackBerry.

If you need to create an application, Enyo is a choice you may want to consider. You can learn more at enyojs.com, and if you are a fan of Haxe-based development, there are externs for Enyo 1.0 on haxelib which can enable you to use the framework while also benefiting from the many advantages of haxe JS.

Although most of the samples for Enyo are applications, at least one sample, “Pirate Pig,” is that of a game. It is a quirky game that uses similar mechanics to Bejeweled. You can view the original version here:

http://www.enyojs.com/samples/piratepig/

The Challenge

I wanted to discover how difficult it would be to create the same game using NME. I would not use any of the original Javascript source code, but instead would use the same assets to recreate the same mechanics.

In the spirit of a game jam, I wanted to create the game in two days. In the interest of supporting my wife, I wanted to also keep it during the day instead of working late. Continue reading NME Game Example: “Pirate Pig”

NME + wxWindows

In addition to writing HXCPP, NME and most of the SWF library, Hugh Sanderson also has a “waxe” project that I’ve never really played with. On the Haxe mailing list, Luke Davies asked if it was possible to display a “file.browse” dialog box from NME.

This hasn’t been possible, but Hugh pointed out that waxe could make this possible, and offered suggestions for anyone interested in trying it out. I’ve known about this project for a while, and also known that wxWidgets powers well known cross-platform applications, such as FileZilla, but somehow my interest was never piqued until I read these instructions last night.

So I downloaded waxe from SVN and lept into it. Thanks to Hugh’s instructions, I was able to get wxWindows and the waxe NDLL compiling on Windows. This morning, I worked on getting it to compile for Linux, but there are still a few linker errors that need to be sorted. Nevertheless, with some changes I was able to create a Cocoa-based OS X build… and as far as I have tested, it works! Continue reading NME + wxWindows

Joystick and Gamepad Support for NME

Ask and you shall receive.

I know that some people have wished NME could support a joystick or gamepad natively. I am very happy to announce that joystick/gamepad support was added today in the development builds for NME!

Earlier I was not able to find my gamepad, so I installed MotioninJoy and plugged in my PS3 controller.

Please check out my example project, and let me know what you think about the API. There is a new JoystickEvent class, which you use to listen to events from the stage, similar to KeyboardEvents. You can listen for JoystickEvent.AXIS_MOVE, JoystickEvent.BALL_MOVE, JoystickEvent.BUTTON_DOWN, JoystickEvent.BUTTON_UP or JoystickEvent.HAT_MOVE.

If the device is a gamepad, the analog joystick will usually appear as an axis, and the d-pad will appear as a hat. Continue reading Joystick and Gamepad Support for NME

Sample Native Extension for NME

I created a native extension sample for NME this morning that I would like to share with you:

http://www.joshuagranick.com/code/haxe/NME%20Extension%20Test.zip

Have you ever wanted to access your own code, written in C, C++ or Objective-C? This sample should help illustrate the “glue” that makes it possible to write and access native code from Haxe. I’ve also added a new “extension” tag to the NMML project file format which should make the workflow even easier. Continue reading Sample Native Extension for NME

Adding Screen Density Support to MineHX

MineHX was created a year ago. At the time, my phone used a native resolution of 320 x 480. Like most games, MineHX was designed specifically for only one or two devices.

Supporting multiple screen sizes, and worse, multiple screen densities, can be rather complicated. I’ve done some work recently to make this process less painful, and would like to share with you a sample from MineHX. The whole game is not completed at multiple resolutions, but there is still enough here that you can borrow or improve the concept for your own games.

http://www.joshuagranick.com/code/haxe/MineHX%20Sample%20(10-03-2011).zip Continue reading Adding Screen Density Support to MineHX

Cross-Platform Game Running in Flash *and* HTML5

I am very happy to share with you some of the first-fruits of integration between NME and Jeash — a working game!

Yesterday, I began the process of experimenting with adding an HTML5 target, thanks to Jeash. I am really impressed with how the project has developed since I last tried it out. Niel Drummond has done a great with the framework, as well as all others who have contributed to Jeash.

Similar to other targets in NME, I am publishing to Javascript using “haxelib run nme test MineHX.nmml html5″. Embedding assets as well as managing the build process is handled by the tool. I have unified Jeash with other targets, so you can still use a single API for loading embedded fonts, accessing bitmaps or playing sounds. The platform differences are being handled under the hood.

Flash

http://www.joshuagranick.com/examples/minehx/flash/

HTML5

http://www.joshuagranick.com/examples/minehx/html5/

NME 3: Flash, C++ and now HTML5

From the beginning, Haxe was created to be a “multi-platform programming language.”

NME relies on Haxe for reliable compilation to Flash and C++, but these aren’t the only languages Haxe supports. Meanwhile, a project (you may have heard of) called Jeash used Haxe to mirror the Flash API… but for Javascript.

For everyone who is excited by HTML5, you can now publish to Flash, C++ and Canvas as easy as…

haxelib run nme test MyProject.nmml flash
haxelib run nme test MyProject.nmml ios -simulator
haxelib run nme test MyProject.nmml webos
haxelib run nme test MyProject.nmml android
haxelib run nme test MyProject.nmml cpp
haxelib run nme test MyProject.nmml cpp -64
haxelib run nme test MyProject.nmml html5

Here is my previous “Actuate Example,” running in Flash and in Canvas as a comparison:

http://www.joshuagranick.com/examples/actuate/circles/flash/
http://www.joshuagranick.com/examples/actuate/circles/canvas/

Android, iOS, webOS (and More!) — Cross-Platform Made Easy

“…One codebase for all platforms? A dream come true.”

 – from Twitter, 19 minutes ago

Going cross-platform is getting even easier. The latest builds of NME make it possible to cross-compile to Android, iOS, webOS and Windows, right out-of-the-box. Support for Mac OS, Linux, Flash, Neko and GPH should also be re-integrated soon. This is due, in no small part, to Nicolas Cannasse, who created the Haxe language and compiler, and Hugh Sanderson, who created NME for Haxe.

Update (01/16/2012): If you would like to get started with NME, the best resource is http://www.haxenme.org/developers/get-started. There are automated installers for Windows, Mac and Linux, as well as a new “nme setup” command which simplifies the install of supporting tools for Windows, webOS, Android and other targets. These were not available at the time that I created this blog post.

Pictured: Actuate Example (Haxe) running on Windows 7, an HP TouchPad, an HP Veer 4G, an LG Optimus S and the Xcode 4 iPhone simulator

This is a screenshot of my previous Actuate example, running on Windows, webOS, Android and the iPhone simulator. With the NME install tool, do you want to know how easy this is? Of course you do: Continue reading Android, iOS, webOS (and More!) — Cross-Platform Made Easy

Getting Started with haXe for Flash, webOS, and Windows/Mac/Linux

They aren’t joking when they say that haXe is a multi-platform programming language.

Here is an example project which will compile to Flash or webOS from Windows, OS X or Linux. It even compiles as a native desktop application for OS X or Linux, and almost for Windows — I just need to fix a couple of header references.

http://www.joshuagranick.com/code/haxe/Getting%20Started.zip

It’s pretty simple to get things started. I’ll walk you through the steps it takes to get things configured for each platform. Continue reading Getting Started with haXe for Flash, webOS, and Windows/Mac/Linux

Installing haXe (Flash/Canvas/PHP/C++)

You might not be familiar with haXe, but you should be familiar with its compiler targets. haXe can publish the same project to Flash, Javascript, PHP, C++, Neko, and in the future it will support Java and C#. I have written games myself which run in Flash and webOS without platform specific code. It is an amazing tool for focusing on making great games and not being caught up instead with how to make them work.

Writing code in haXe is similar to writing Javascript or Actionscript, but everything is typed and the compiler provides code completion. You could write a game that targets Javascript and HTML5 Canvas, or you could leverage server side targets like PHP or Neko so that you can share your game classes on both the front-end and back-end. Create a game that runs on Facebook and runs on an iPad or TouchPad.

I know other developers who use haXe to write Javascript with compile-time error checking, or to create libraries which are compatible with both Javascript and PHP. Other developers use haXe to add new features to Flash like macros, generics and inlining, or to better take advantage of the memory functions exposed by Adobe Alchemy in Flash Player, which are not normally accessible through Actionscript. I believe that haXe has an exciting future as it continues to mature. Being able to cross-compile applications to the web, to iOS, webOS and Android with native performance is very compelling. haXe applications on these platforms run as quickly as native applications because they are still C++ applications built with the same compilers.

Unlike other cross-platform tools, the code is MIT licensed, so you have no licensing fees and you aren’t limited. haXe has a passionate open-source community behind it, and the code is unlocked, so it isn’t hard to delve into the underlying code if you want to add a new feature. Continue reading Installing haXe (Flash/Canvas/PHP/C++)