Haxe Game Development Essentials

Book description

Create games on multiple platforms from a single codebase using Haxe and the HaxeFlixel engine

About This Book

  • Learn the modern, cross-platform language Haxe to build games without any trouble
  • Create engaging 2D games that are compatible with desktop, web, and mobile platforms
  • Learn how to speed up your workflow with OpenFL and HaxeFlixel using this useful and compact guide

Who This Book Is For

This book is for game developers with some experience 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 running quickly, this book is for you. Having prior experience with a language similar to Haxe, such as ActionScript or JavaScript will help, but isn't required.

What You Will Learn

  • Understand the fundamentals of the Haxe programming language
  • Set up a development environment that will work on Windows, Mac, and Linux
  • Create fun 2D games using OpenFL and HaxeFlixel
  • Understand how to implement a user interface
  • Enhance the gameplay experience with cool animations
  • Improve immersion by adding sound
  • Make your game modular and easily expandable using configuration files
  • Compile games that will work on desktop, web, and mobile platforms

In Detail

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.

Style and approach

Since this book is aimed at people who have worked on games before, this book is written in a way that will get you quickly up to speed with a new set of tools, but will still be accessible for less experienced developers. Each chapter covers an essential milestone in building a game from start to finish. The chapters move in a logical fashion, starting with the basics of Haxe development and ending with preparing a game for deployment.

Table of contents

  1. Haxe Game Development Essentials
    1. Table of Contents
    2. Haxe Game Development Essentials
    3. Credits
    4. About the Author
    5. Acknowledgements
    6. About the Reviewers
    7. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    8. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Downloading the color images of this book
        3. Errata
        4. Piracy
        5. Questions
    9. 1. Getting Started
      1. What's Haxe?
        1. OpenFL
        2. HaxeFlixel
      2. Installation
        1. Installing Haxe
        2. OpenFL
        3. Setting up an IDE
        4. Installing HaxeFlixel
      3. Setting up target platforms
        1. Flash
        2. Android
        3. iOS
        4. Desktop
      4. Hello World
        1. Creating a project
        2. Running the project
        3. Copying assets
        4. Making changes
      5. Summary
    10. 2. Building a New Game
      1. The Haxe syntax
        1. Data types and structures
        2. Operators
        3. Access modifiers
        4. Variables
        5. Functions
        6. The for loops
        7. Classes
      2. Setting up a new HaxeFlixel project
        1. Creating the new project
        2. The anatomy of our project
        3. Changing settings
        4. Adding assets
      3. Adding a background and basic UI
      4. Making enemies
        1. Creating the enemy class
        2. Adding variables
        3. Setting up the display
        4. Creating the spawn timer
      5. Instantiating enemies and adding interaction
        1. Adding new imports
        2. Adding variables
        3. Creating instances and adding mouse events
      6. Creating the end screen
        1. Creating the end screen class
        2. Adding variables
        3. Adding the background and score text
      7. Restarting the level
      8. Implementing the game timer
        1. Importing the end screen
        2. Adding variables
        3. Creating the level timer
        4. Creating the timer callback function
      9. Summary
    11. 3. Dealing with Menus and Screen Flow
      1. Adding new assets
        1. Changing the default state
      2. Building the splash screen
        1. Adding imports
        2. Creating variables
        3. Adding sprites
        4. Adding instructions
        5. Starting the animation sequence
        6. Creating the next stage of the sequence
        7. Finishing the sequence
        8. Navigating back to the game
      3. Updating the level end screen
        1. Adding imports
        2. Adding variables
        3. Housekeeping
        4. Adding the group and setting up the window
        5. Adding scores
        6. Adding the play again button
        7. Showing the best score sprite
        8. Creating the animation sequence
      4. Creating the new game HUD
        1. Creating the GameHUD class
        2. Adding imports
        3. Adding variables
        4. Laying things out
        5. Changing the score
      5. Adding the new game HUD
        1. Adding imports
        2. Adding variables
        3. Housekeeping
        4. Adding the HUD and enemy group
      6. Summary
    12. 4. Delving into Animations and Gameplay
      1. Object pooling
      2. Project updates
        1. Adding new assets
        2. Updating the project settings
      3. Creating the explosion effects
        1. Creating the class
        2. Adding imports
        3. Creating variables
        4. Setting up Texture Packer data
        5. Adding sprites
        6. Creating a particle emitter
        7. Adding everything to the group
        8. Starting the explosion sequence
        9. Showing the explosion bulb
        10. Showing smoke and completing the animation
        11. Preparing for object pooling
      4. Making muzzle flashes
        1. Creating the class
        2. Adding imports
        3. Creating variables
        4. Adding sprites
        5. Playing the flash
        6. Showing the rings
      5. Updating enemies
        1. Adding imports
        2. Adding variables
        3. Adding animation
        4. Resetting the spawn position
        5. Updating the onSpawn function
        6. Adding death functionality
      6. Creating projectiles
        1. Creating the class
        2. Adding imports
        3. Creating variables
        4. Displaying the sprite and setting the velocity
      7. Making the player character
        1. Creating the class
        2. Adding imports
        3. Creating variables
        4. Adding animation
        5. Making the projectile pool
        6. Creating the muzzle flash
        7. Starting the shoot timer
        8. Shooting projectiles
        9. Handling player input
        10. Building movement functions
        11. Handling player death
      8. Setting health on the HUD
        1. Changing hearts
      9. Adding everything to PlayState
        1. Adding imports
        2. Adding variables
        3. Cleaning things up
        4. Adding the scrolling backdrop
        5. Creating and adding the player
        6. Creating an explosion object pool
        7. Killing enemies
        8. Updating the score
        9. Detecting collisions
        10. Handling collisions between projectiles and enemies
        11. Handling collisions between the player and enemies
      10. Summary
    13. 5. Adding Sound
      1. Project updates
        1. Adding new assets
        2. Updating the project settings
      2. Creating sound constants
        1. Creating the class
        2. Creating sound ID constants
        3. Creating volume constants
      3. Building the sound manager class
        1. Creating the class
        2. Adding imports
        3. Implementing the singleton pattern
      4. Adding music
        1. Creating playback functions
        2. Calling playback functions
      5. Adding menu sounds
        1. Creating playback functions
        2. Calling playback functions
      6. Adding gameplay sounds
        1. Creating variables
        2. Creating functions
        3. Calling playback functions
      7. Summary
    14. 6. Working with Configuration Files
      1. JSON versus XML
      2. Project updates
        1. Adding new assets
      3. Understanding the JSON configuration file
        1. A simple example
        2. Looking at the JSON format
      4. Building the enemy spawner
        1. Creating the enemy spawner class
        2. Adding imports
        3. Adding variables
        4. Parsing JSON data
        5. Populating the pool
      5. Spawning enemies
      6. Adding movement patterns to enemies
        1. Adding imports
        2. Adding variables
        3. Removing old functionality
        4. Creating the startPattern function
        5. Updating onSpawn and resetSpawn
      7. Updating PlayState
        1. Removing old functionality
        2. Using EnemySpawner
      8. Understanding the XML file
        1. Looking at the file's contents
      9. Pulling string data from XML
        1. Building the Strings class
        2. Handling XML data
        3. Building the StringIDs class
      10. Replacing strings
        1. Updating MenuState
        2. Updating GameHUD
      11. Updating LevelEndScreen
      12. Summary
    15. 7. Deploying to Multiple Platforms
      1. Building for Flash
        1. Deploying to the Web
      2. Building for Windows
      3. Building for OS X
      4. Building for Android
      5. Building for iOS
        1. Xcode setup
        2. Setting up a certificate
        3. Setting up an App ID
        4. Registering a device
        5. Creating a provisioning profile
        6. Running the game on iOS
      6. Summary
    16. 8. What's Next?
      1. Expanding the game
        1. Level-based gameplay
        2. Power-ups and collectibles
        3. More enemies and bosses
      2. Exploring advanced features
        1. Gamepads
        2. Physics
        3. Tilemaps
      3. Continuing on with learning resources
        1. Haxe
        2. OpenFl
        3. HaxeFlixel
        4. Community resources
      4. Summary
    17. Index

Product information

  • Title: Haxe Game Development Essentials
  • Author(s): Jeremy McCurdy
  • Release date: November 2015
  • Publisher(s): Packt Publishing
  • ISBN: 9781785289781