Haxe Game Development Essentials
()
About this ebook
Related to Haxe Game Development Essentials
Related ebooks
CRYENGINE Game Development Blueprints Rating: 0 out of 5 stars0 ratingsSFML Game Development By Example Rating: 0 out of 5 stars0 ratingsLibGDX Game Development By Example Rating: 0 out of 5 stars0 ratingsHTML5 Game Development with GameMaker Rating: 0 out of 5 stars0 ratingsProcedural Content Generation for C++ Game Development Rating: 3 out of 5 stars3/5Source SDK Game Development Essentials Rating: 0 out of 5 stars0 ratingsSFML Game Development Rating: 0 out of 5 stars0 ratingsLearning Libgdx Game Development Rating: 0 out of 5 stars0 ratingsSFML Blueprints Rating: 0 out of 5 stars0 ratingsInstant HTML5 2D Platformer Rating: 0 out of 5 stars0 ratingsUnity Multiplayer Games Rating: 5 out of 5 stars5/5Game Development with Three.js Rating: 0 out of 5 stars0 ratingsOpenGL Game Development By Example Rating: 0 out of 5 stars0 ratingsBuilding Android Games with Cocos2d-x Rating: 0 out of 5 stars0 ratingsAndroid Game Programming by Example Rating: 0 out of 5 stars0 ratingsMastering LibGDX Game Development Rating: 0 out of 5 stars0 ratingsLearning LibGDX Game Development - Second Edition Rating: 0 out of 5 stars0 ratingsMastering SFML Game Development Rating: 0 out of 5 stars0 ratingsGameMaker Programming By Example Rating: 0 out of 5 stars0 ratingsPhaser III Game Prototyping Rating: 0 out of 5 stars0 ratingsUnity 5 for Android Essentials Rating: 4 out of 5 stars4/5Unity Game Development Scripting Rating: 0 out of 5 stars0 ratingsiOS Game Development By Example Rating: 0 out of 5 stars0 ratingsDeveloping Turn-Based Multiplayer Games: with GameMaker Studio 2 and NodeJS Rating: 0 out of 5 stars0 ratingsLearning C++ by Creating Games with UE4 Rating: 3 out of 5 stars3/5Mastering Unity Scripting Rating: 0 out of 5 stars0 ratingsHTML5 Game Development by Example: Beginner's Guide - Second Edition Rating: 1 out of 5 stars1/5Phaser.js Game Design Workbook: Game development guide using Phaser JavaScript Game Framework Rating: 0 out of 5 stars0 ratingsJavaScript Mobile Application Development Rating: 0 out of 5 stars0 ratingsBox2D for Flash Games Rating: 0 out of 5 stars0 ratings
Programming For You
Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 0 out of 5 stars0 ratingsGrokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Hacking: Ultimate Beginner's Guide for Computer Hacking in 2018 and Beyond: Hacking in 2018, #1 Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5The Unofficial Guide to Open Broadcaster Software: OBS: The World's Most Popular Free Live-Streaming Application Rating: 0 out of 5 stars0 ratingsPYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Python Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratingsTeach Yourself C++ Rating: 4 out of 5 stars4/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Web Designer's Idea Book, Volume 4: Inspiration from the Best Web Design Trends, Themes and Styles Rating: 4 out of 5 stars4/5The Little SAS Book: A Primer, Sixth Edition Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5
Reviews for Haxe Game Development Essentials
0 ratings0 reviews
Book preview
Haxe Game Development Essentials - McCurdy Jeremy
Table of Contents
Haxe Game Development Essentials
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started
What's Haxe?
OpenFL
HaxeFlixel
Installation
Installing Haxe
OpenFL
Setting up an IDE
Installing HaxeFlixel
Setting up target platforms
Flash
Android
iOS
Desktop
Hello World
Creating a project
Running the project
Copying assets
Making changes
Summary
2. Building a New Game
The Haxe syntax
Data types and structures
Operators
Access modifiers
Variables
Functions
The for loops
Classes
Setting up a new HaxeFlixel project
Creating the new project
The anatomy of our project
Changing settings
Adding assets
Adding a background and basic UI
Making enemies
Creating the enemy class
Adding variables
Setting up the display
Creating the spawn timer
Instantiating enemies and adding interaction
Adding new imports
Adding variables
Creating instances and adding mouse events
Creating the end screen
Creating the end screen class
Adding variables
Adding the background and score text
Restarting the level
Implementing the game timer
Importing the end screen
Adding variables
Creating the level timer
Creating the timer callback function
Summary
3. Dealing with Menus and Screen Flow
Adding new assets
Changing the default state
Building the splash screen
Adding imports
Creating variables
Adding sprites
Adding instructions
Starting the animation sequence
Creating the next stage of the sequence
Finishing the sequence
Navigating back to the game
Updating the level end screen
Adding imports
Adding variables
Housekeeping
Adding the group and setting up the window
Adding scores
Adding the play again button
Showing the best score sprite
Creating the animation sequence
Creating the new game HUD
Creating the GameHUD class
Adding imports
Adding variables
Laying things out
Changing the score
Adding the new game HUD
Adding imports
Adding variables
Housekeeping
Adding the HUD and enemy group
Summary
4. Delving into Animations and Gameplay
Object pooling
Project updates
Adding new assets
Updating the project settings
Creating the explosion effects
Creating the class
Adding imports
Creating variables
Setting up Texture Packer data
Adding sprites
Creating a particle emitter
Adding everything to the group
Starting the explosion sequence
Showing the explosion bulb
Showing smoke and completing the animation
Preparing for object pooling
Making muzzle flashes
Creating the class
Adding imports
Creating variables
Adding sprites
Playing the flash
Showing the rings
Updating enemies
Adding imports
Adding variables
Adding animation
Resetting the spawn position
Updating the onSpawn function
Adding death functionality
Creating projectiles
Creating the class
Adding imports
Creating variables
Displaying the sprite and setting the velocity
Making the player character
Creating the class
Adding imports
Creating variables
Adding animation
Making the projectile pool
Creating the muzzle flash
Starting the shoot timer
Shooting projectiles
Handling player input
Building movement functions
Handling player death
Setting health on the HUD
Changing hearts
Adding everything to PlayState
Adding imports
Adding variables
Cleaning things up
Adding the scrolling backdrop
Creating and adding the player
Creating an explosion object pool
Killing enemies
Updating the score
Detecting collisions
Handling collisions between projectiles and enemies
Handling collisions between the player and enemies
Summary
5. Adding Sound
Project updates
Adding new assets
Updating the project settings
Creating sound constants
Creating the class
Creating sound ID constants
Creating volume constants
Building the sound manager class
Creating the class
Adding imports
Implementing the singleton pattern
Adding music
Creating playback functions
Calling playback functions
Adding menu sounds
Creating playback functions
Calling playback functions
Adding gameplay sounds
Creating variables
Creating functions
Calling playback functions
Summary
6. Working with Configuration Files
JSON versus XML
Project updates
Adding new assets
Understanding the JSON configuration file
A simple example
Looking at the JSON format
Building the enemy spawner
Creating the enemy spawner class
Adding imports
Adding variables
Parsing JSON data
Populating the pool
Spawning enemies
Adding movement patterns to enemies
Adding imports
Adding variables
Removing old functionality
Creating the startPattern function
Updating onSpawn and resetSpawn
Updating PlayState
Removing old functionality
Using EnemySpawner
Understanding the XML file
Looking at the file's contents
Pulling string data from XML
Building the Strings class
Handling XML data
Building the StringIDs class
Replacing strings
Updating MenuState
Updating GameHUD
Updating LevelEndScreen
Summary
7. Deploying to Multiple Platforms
Building for Flash
Deploying to the Web
Building for Windows
Building for OS X
Building for Android
Building for iOS
Xcode setup
Setting up a certificate
Setting up an App ID
Registering a device
Creating a provisioning profile
Running the game on iOS
Summary
8. What's Next?
Expanding the game
Level-based gameplay
Power-ups and collectibles
More enemies and bosses
Exploring advanced features
Gamepads
Physics
Tilemaps
Continuing on with learning resources
Haxe
OpenFl
HaxeFlixel
Community resources
Summary
Index
Haxe Game Development Essentials
Haxe Game Development Essentials
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
Credits
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
About the Author
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.
Acknowledgements
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.
About the Reviewers
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.
www.PacktPub.com
Support files, eBooks, discount offers, and more
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
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.
Why subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Free access for Packt account holders
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.
Preface
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!
What this book covers
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