Book Image

Haxe Game Development Essentials

Book Image

Haxe Game Development Essentials

Overview of this book

Haxe is a powerful and high-level multi-platform language that's incredibly easy to learn. Used by thousands of developers and many high-profile companies, Haxe is quickly emerging as a forerunner in the area of cross-platform programming. OpenFL builds on top of Haxe to make developing for multiple platforms quick and painless. HaxeFlixel provides you with the tools you need to build amazing 2D games easier than ever before. Cross-platform development has been supercharged using the Haxe programming language, making it increasingly easy and hassle-free to develop multi-platform games. If you've programmed games before and want to learn out how to deliver games across multiple platforms, or develop games faster, then Haxe Game Development Essentials is the book for you. It starts by showing you how to set up your development environment, then running you through some Haxe language fundamentals, and finally taking you through the process of programming a game from start to finish. You will learn how to create a side scrolling shooter game using HaxeFlixel. Next you will learn to enhance the game with new gameplay features, user interfaces, animations, sound, and configuration files to make your game expandable. Once your game is built and ready, you will learn how to deploy it to web, Android, iOS, and desktop systems. By the end of this book, you will be confident about creating multi-platform games using Haxe, OpenFL, and HaxeFlixel in a faster and easier way.
Table of Contents (16 chapters)
Haxe Game Development Essentials
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Installation


Now that you have a good understanding of what we'll be using, let's start installing what we'll need. Haxe, OpenFL, and HaxeFlixel are all designed to be easy to set up, so this is going to be pretty straightforward.

Installing Haxe

Go to http://haxe.org/download/ and download the installer for your operating system. Run the installer; be sure to install both Haxe and Neko when given the option.

This will install the Haxe framework, which includes Haxelib, a useful tool for installing Haxe frameworks and libraries. You will typically use this to install all Haxe libraries, which will make the installation of OpenFL and HaxeFlixel incredibly straightforward.

OpenFL

To install OpenFL, open a command window (or terminal on OS X and Linux). Next, run the following commands:

haxelib install openfl
haxelib -notimeout run openfl setup

These two commands will download, install, and set up the OpenFL framework and all of the libraries it needs. The notimeout flag prevents the setup from timing out before it completes. This is useful because the OpenFL setup will download quite a number of files, and it can time out if your internet connection is a little slow.

When asked if you want to install OpenFL, press Y. On Mac and Linux, you may be asked to enter your password. After this, OpenFL will be installed and you'll be good to go!

Setting up an IDE

Before installing HaxeFlixel, it's important to install a code-editing tool, because you will be prompted to choose one during the HaxeFlixel setup. Your operating system will be a factor in choosing the best tool for you.

Windows users are able to use FlashDevelop, which is a fully featured IDE that will work with Haxe out of the box. The best part of using FlashDevelop is that you can debug your games by targeting Flash and using the Flash debug player. This will allow you to put in breakpoints, see console logs, and inspect variables. You can download the latest version by going to http://flashdevelop.org. If you are using Windows, I highly recommend using it.

For Mac and Linux users, the best tool available is Sublime Text 2. It's a solid code-editing tool, though it lacks support for breakpoints, console logs, and variable inspection. You can download the latest version by going to http://sublimetext.com. You can also use Sublime Text on Windows if you prefer it.

To make Sublime Text a more effective Haxe editing tool, you should install the Haxe plugin. The easiest way to install it is using package control, which you can install using the steps located at https://packagecontrol.io/installation#st2.

After installing package control, use Ctrl + Shift + P (Windows or Linux) or cmd + Shift + P (Mac) to bring up the command palette. Start typing in package and then navigate down to Install Package. You will then see a list of available packages to install. Type in Haxe to find the package named Haxe. Install that and you're good to go!

Installing HaxeFlixel

To install HaxeFlixel, run these commands:

haxelib install flixel
haxelib install flixel-tools
haxelib run flixel-tools setup

You will then be prompted several times during the setup. Here's what you should do:

  1. When a command appears asking if you want to set up Flixel, press Y.

  2. When asked if you would like to download flixel-demos and flixel-templates, press Y.

  3. When prompted to enter an author name, either type in your name or leave the field blank. It will automatically use that name when creating project templates.

  4. When asked to choose your default IDE, enter the number corresponding to your development tool of choice.

  5. Choose either Y or N when asked if you want to automatically open created templates and demos with your IDE of choice. This will just immediately open your project in your IDE instead of requiring you to navigate your filesystem.

  6. On Macs, if you chose to have templates and demos automatically open, you will be asked whether or not you want to run a symlink command. Press Y.

If you ever need to change these settings, you can run the Flixel tools setup command again.