20,39 €
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.
Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:
Seitenzahl: 200
Veröffentlichungsjahr: 2015
Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2015
Production reference: 1241115
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78528-978-1
www.packtpub.com
Author
Jeremy McCurdy
Reviewers
Romuald Halasz
Nathan McDonald
Robin Poirier
Acquisition Editors
Harsha Bharwani
Usha Iyer
Content Development Editor
Samantha Gonsalves
Technical Editor
Edwin Moses
Copy Editor
Dipti Mankame
Project Coordinator
Sanchita Mandal
Proofreader
Safis Editing
Indexer
Hemangini Bari
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
Jeremy McCurdy is a game developer who has been making games using ActionScript, C#, and Haxe for over four years. He has developed games targeted at iOS, Android, Windows, OS X, Flash, and HTML5. He has worked on games that have had millions of gameplay sessions, and has built games for many major North American television networks.
He is the games technical lead at REDspace, an award-winning interactive studio that has worked for some of the world's largest brands. They are located in Nova Scotia, Canada, and have been building awesome experiences for 15 years.
I would like to thank my family for constantly pushing me to reach my goals. Thanks go to my parents, Gaile Jodrey and Blaine McCurdy; sisters, Darlene and Gabrielle Therrien; grandparents, Roy and Marg Jodrey; and cousin, Tammy Lucy Prall.
I would also like to thank my college instructor, Sean Morrow, from the Nova Scotia Community College's Truro Campus. He set me on the path to being a programmer twice, taught me the fundamentals of programming, and made learning incredibly fun.
I'd also like to thank my coworkers who pushed me from being a scared little intern to a proper technical lead—Shane Kerr, Thomas Gillis, Armen Abrahamyan, Mike McGraw, Robin Poirier, and Nathan McDonald.
Lastly, I'd like to thank Mike Johnston and Wes Gould, who have given me awesome career opportunities at REDspace and made a workplace that I feel proud to be a part of.
I wouldn't be here writing this now if it weren't for all of these people. They have all made my life as a developer possible, and I honestly can't thank them enough.
Romuald Halasz began his adventure in the world of programming nearly 20 years ago. His passion for writing code was sparked by computer games. He was amazed by them and wanted to learn how they are made in order to bring his own ideas to life. It's been a wonderful experience that involved learning and great amounts of fun.
Throughout his journey, he has explored different segments of the development spectrum, such as web development, enterprise software development, and more recently, mobile development.
He has worked in different companies, from start-ups to multinationals. He has also tried his hand at freelancing. In general, he sees coding as a way of life. It is a journey of learning and giving life to projects, which start with one idea. There is also the satisfaction of people using the products that you have worked on.
Nathan McDonald is a game developer who is currently working at REDspace, where he helps build games using languages and tools such as Haxe, Flambe, and Unity.
I would like to thank Jeremy McCurdy for the opportunity to help him with this book and Robin Poirier for all the help that he's given.
Robin Poirier is a game developer from Nova Scotia, Canada. He works mainly in Haxe/Flambe and Unity3D. He has developed games that deploy for iOS, Android, Flash, and HTML5. He currently works at REDspace as part of their games division.
Specials thanks to Jeremy McCurdy for this opportunity to be part of this book and Nathan McDonald for being a good rubber duck.
For support files and downloads related to your book, please visit www.PacktPub.com.
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.
Developing games that can reach a wide audience can often be a serious challenge. A big part of the problem is figuring out how to make a game that will work on a wide range of hardware and operating systems. This is where Haxe comes in.
Over the course of this book, we'll look at getting started with Haxe and the HaxeFlixel game engine, build a side-scrolling shooter game that covers the core features you need to know, and prepare the game for deployment to multiple platforms.
After completing this book, you will have the skills you need to start producing your own cross-platform Haxe-driven games!
Chapter 1, Getting Started, explains setting up the Haxe and HaxeFlixel development environment and doing a quick Hello World example to ensure that everything is working.
Chapter 2, Building a New Game, looks at the fundamentals of the Haxe language and building the core foundation of our game.
Chapter 3, Dealing with Menus and Screen Flow, helps to set up our game's UI, add simple UI animations, and control the flow between screens.
Chapter 4, Delving into Animations and Gameplay, explains adding sprites and scripted animations and adding the bulk of our gameplay functionality.
Chapter 5, Adding Sound, delves into the aspects of adding music and sound effects to make our animations and gameplay truly engaging.
Chapter 6, Working with Configuration Files, talks of using JSON and XML configuration files to make our game expandable and editing the text far easier.
Chapter 7, Deploying to Multiple Platforms, shows how to take our completed game and build it to work on desktop, web, and mobile platforms.
Chapter 8, What's Next?, looks at game features to expand on and at resources to continue learning.
The introductory chapter of the book will walk you through getting the tools you need to develop with. However, you will need a computer to develop with. You can develop games with Haxe on Apple OS X, Microsoft Windows, or Linux operating systems.
In order to develop a game for a particular operating system, you will need to have access to a machine with it installed to create playable builds. For example, you need to be using OS X to develop a game targeted at OS X.
For mobile platforms, you can use any operating system to develop Android applications, but you will need a Mac running OS X to develop iOS applications. You will also need an iOS device in order to develop for iOS; this can be an iPhone, iPad, or iPod Touch.
This book is for game developers with some experience in programming games on one or more platforms already. If you want to leverage your game development experience on one platform to develop for multiple platforms and to get up and run quickly, this book is for you.
In addition, if you want to learn how using Haxe, OpenFL, and HaxeFlixel can make multiplatform development faster and easier, this book will show you.
Having prior experience with a language similar to Haxe, such as ActionScript or JavaScript, will help, but isn't required.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Open MenuState.hx and navigate inside the Create function."
A block of code is set as follows:
Any command-line input or output is written as follows:
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "If you're using FlashDevelop, you can create a class by right-clicking on the source folder and going to Add | New Class."
Warnings or important notes appear in a box like this.
Tips and tricks appear like this.
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from http://www.packtpub.com/sites/default/files/downloads/Haxe_GameDevelopment_Essentials_ColorImages.pdf.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.
In this chapter, we're going to see what Haxe is, how it will enable you to create awesome multiplatform games, and then we'll install all of the tools we'll need to develop with. After setting things up, we'll work with a quick Hello World example to make sure that everything works and we're ready to start making games!
Here's a rundown of the sections in this chapter:
Haxe is an open source programming toolkit that is composed of a language, compiler, and command-line interface. It is heavily inspired by ActionScript 3, with some tweaks here and there to add functionality. It also draws some inspiration from C#. It's so similar that at a glance, Haxe code could easily be confused for ActionScript. This doesn't mean that you have to know ActionScript to learn Haxe, but it does help. Knowing an object-oriented language, such as C# or Java, will also give you a leg up.
Haxe compiles to several different platforms, allowing you to have one codebase that will work in browsers, desktop operating systems, and on mobile devices.
In case you were wondering about the pronunciation, Haxe is pronounced Hex, though many people pronounce it Hacks.
OpenFL is a framework built on top of Haxe; it adds additional API functionality and provides build tools to streamline your workflow. Most of the API changes it introduces are meant to help mimic the ActionScript 3 API. For example, it adds support for Flash's Stage 3D mode, text formatting, and bitmap data.
OpenFL also uses the Lime library, which is a library that helps to ensure consistent cross-platform support so that builds for different platforms don't behave radically differently. It covers things such as cross-platform audio, rendering, and asset management.
Some of our build commands will be executed using Lime, and that's pretty much all we'll be directly using it for.
HaxeFlixel is a game engine that's built on top of OpenFL. It was originally based on the ActionScript 3 game engine named Flixel, and has since branched off on its own. It's well documented and has a solid community, making it an ideal engine for people who want to learn how to make games with Haxe.
HaxeFlixel supports the following features:
That's just a handful of the features of the engine; it's very robust. HaxeFlixel will help us start building high-quality games much faster than doing everything from scratch.
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.
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.
To install OpenFL, open a command window (or terminal on OS X and Linux). Next, run the following commands:
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!
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!
To install HaxeFlixel, run these commands:
You will then be prompted several times during the setup. Here's what you should do:
