Deploying C++ to JavaScript using Emscripten

If you paid attention during the post-GDC news, you probably heard that Epic Games and Mozilla teamed up to get the Unreal Engine running in the browser, without plugins, in a matter of four days. The secret? Emscripten.

Alon Zakai has worked three years on Emscripten, and its an amazing piece of software.

Literally, you take C++ (or technically, something that compiles to LLVM), and out comes JavaScript. Not only can you do basic code, you can take large, complex projects with myriad dependencies, and actually run it in the browser.

Let’s take one of my previous samples, and port it to the browser. Ready? Continue reading Deploying C++ to JavaScript using Emscripten

Adding Inline C++ to Haxe Code

On the NME forums this morning, redannick asked if it was possible to get the current timezone offset, using Haxe.

Unfortunately, I discovered that getTimezoneOffset() is not part of the Haxe Date class. Perhaps this will be available in Haxe 3. For the meantime, I found a solution using the @:headerCode and @:functionCode tags.

This was my first experience using compiler metadata tags for C++. This is really powerful. Continue reading Adding Inline C++ to Haxe Code

Using Threads with NME

There has been a good amount of discussion recently about concurrency (multi-threading), now that Actionscript has added support in the new Flash Player release.

Haxe already supports threading when you are using the C++ or Neko targets.

The following samples will not work for Flash or HTML5, but will create and manage communication between threads on the Windows, Mac, Linux, iOS, Android, BlackBerry and webOS targets for NME.

Continue reading Using Threads with NME

Adding the BlackBerry C/C++ Native Target in 48 Hours

I am one of the lead developers for NME, a cross-platform, open-source framework.

If you have not heard of NME, it targets Windows, Mac, Linux, iOS, Android, BlackBerry, webOS, Flash and HTML5 from a single codebase. It does not require a virtual machine, and does not use a scripting language like Lua or Javascript, other than the HTML5 target. It reliably supports each platform using native C++ and OpenGL, SWF bytecode or Javascript, thanks to the incredible Haxe programming language.

The BlackBerry target is the newest platform we support. It took me less than two days to add. Continue reading Adding the BlackBerry C/C++ Native Target in 48 Hours

Getting Started with Haxe/C++ and NME in MonoDevelop

If you have not done so already, follow this post to install Haxe, NME and MonoDevelop.

If you would like to make a visual application, NME provides an array of features beyond the standard Haxe/C++ toolset. NME uses OpenGL, Freetype, libpng, libjpeg, cURL, SDL and other libraries to provide a Flash-similar API for C++ targets. NME is also designed to build applications for Flash and is compatible with Jeash, a library for HTML5 applications.

We can create a new application by going to File > New > Solution in MonoDevelop.

Now we are ready to write some code. Unlike a traditional Haxe/C++ project, the NME template extends the “nme.display.Sprite” class, which is similar to the Sprite class in Flash. We can begin by adding a simple shape, similar to how we would draw a rectangle in Flash: Continue reading Getting Started with Haxe/C++ and NME in MonoDevelop

Getting Started with Haxe/C++ in MonoDevelop

If you have not already, follow this post to install Haxe and MonoDevelop on your system.

To begin a new Haxe/C++ project, open MonoDevelop then go to File > New > Solution

You can select the “Empty Haxe/C++ Project” template, and enter a name and location for your new project. Continue reading Getting Started with Haxe/C++ in MonoDevelop

How to Create an NME Extension

One of the things that I love about NME is that it is easy to extend. Unfortunately, there is not much documentation on the subject, so I want to take a few minutes to help describe what you can do with an NME extension, and how to create one. Trust me, it is not difficult.

include.nmml

Beginning with NME 3.2, all you need to make an extension is add a file called “include.nmml.” This file is processed just like an ordinary NMML project file, with the exception that paths are relative to where your extension is located.

For example, in the “Test” extension I have created, this is my “include.nmml” file:

<?xml version="1.0" encoding="utf-8"?>
<project>
 
	<ndll name="test" />
	<java path="project/android" />
 
</project>

You could include assets, defines, haxelib dependencies, NDLL references, Java code… practically anything you can define from an ordinary NMML project file for NME, you can define using your extension. Continue reading How to Create an NME Extension

Embedding SWFs Makes NME Meme-Friendly

The latest SWF embedding support in NME makes it that much easier to recreate (or create!) your favorite meme:

var cat = new NyanCatAnimation ();
addChild (cat);
 
var theme = Assets.getSound ("assets/Nyan Cat Theme.mp3");
theme.play (0, -1);

When you mark a symbol in Flash to “Export for ActionScript”, you can choose  a class name. In the example above, my MovieClip was exported using “NyanCatAnimation” as the class name. Continue reading Embedding SWFs Makes NME Meme-Friendly

7 Useful Utilities For Your Next NME Application

I have been going through code library to find more tools I could bring to Haxe. I am happy to share some new libraries, as well as a few old ones, which may be helpful in your next (or current) NME (or Haxe) project.

Actuate

If you have used NME before, you probably have heard of Actuate. Simply put, Actuate is a “tween” library, designed to automatically transition objects from one value to another. This works for animation, of course, but is also useful for fading sound, adjusting filters or setting a quick timer.

Two years ago, Actuate was my bread-and-butter library, like (I would argue) tween libraries should be for a Flash developer. It was the culmination of using many kinds of libraries in the best, and actually performed faster than GreenSock’s TweenMax and TweenLite libraries by a fair margin. Most of all, I made sure to give Actuate a “set it and forget it” reliability I had come to appreciate from using Zeh Fernando’s famed Tweener library. Continue reading 7 Useful Utilities For Your Next NME Application