Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Haxe Game Development Essentials

You're reading from   Haxe Game Development Essentials Create games on multiple platforms from a single codebase using Haxe and the HaxeFlixel engine

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher
ISBN-13 9781785289781
Length 188 pages
Edition 1st Edition
Concepts
Arrow right icon
Toc

Table of Contents (10) Chapters Close

Preface 1. Getting Started FREE CHAPTER 2. Building a New Game 3. Dealing with Menus and Screen Flow 4. Delving into Animations and Gameplay 5. Adding Sound 6. Working with Configuration Files 7. Deploying to Multiple Platforms 8. What's Next? Index

Hello World

Now that we have everything we need installed, we should make sure that Haxe, OpenFL, and HaxeFlixel are all up and running. To do this, we'll create a new project using the command line, run it, and then add an image to the screen to ensure that we can make changes.

Creating a project

To create a project, open up a command or terminal window and navigate to the folder in which you want your game's folder to be created.

After doing this, enter this command:

flixel tpl -n "HelloWorld"

This will create a new folder using the standard HaxeFlixel project template. It will also create project files for your code-editing tool of choice, allowing for quick integration out of the box.

Tip

If HaxeFlixel doesn't automatically open your project in your code-editing tool, open it in the tool manually. For FlashDevelop users, double-click on the .hxproj file in the project's folder. For Sublime Text users, drag your project's folder into an empty Sublime window.

A number of Haxe classes with the file extension .hx will be created. These are the base files you need to get a basic HaxeFlixel project up and running. We'll be going over the project's structure throughout the book, so it's not important to know what everything means right now.

Running the project

Now that we have a project set up, we can run it to see what we get out of the box.

If you're running FlashDevelop, select Debug from the drop-down list next to the play button and then select flash from the drop-down list next to that. After this, hit the play button to run your project.

For Sublime Text users, you can press Ctrl + Enter to run the project using the Haxe package that was installed earlier.

To create a build using the command line, navigate to your project's folder and enter this command:

lime test flash

The project should build and then open with your operating system's default application for running .swf files. When the .swf file loads, you'll briefly see the HaxeFlixel logo and then you'll be presented with a blank screen.

Copying assets

We're going to need the image that we want to display, so let's get that now. In the assets provided for this chapter, there is an image named HelloWorld.png. Copy it to the images folder under assets in your project's directory.

Making changes

Now that we have the image copied to the template project, let's add the traditional Hello World image to the screen.

Open MenuState.hx and navigate to the Create function. It will look like this:

override public function create():Void
{
  super.create();
}

After super.create();, add the following lines:

var helloWorldText = new FlxSprite();
helloWorldText.loadGraphic(AssetPaths.HelloWorld__png);
add(helloWorldText);

This will create a new variable of the FlxSprite class. It will then load in the image we just copied over, and then finally add the image to the screen. We'll go into more detail about how to use the FlxSprite class and work with loaded assets later, but that's a quick rundown of what's happening.

All that's left to do is to run the project to see your changes! In FlashDevelop, you just need to press the play button. For Sublime Text users, press Ctrl + Enter.

To create a build using the command line, enter the test command again:

lime test flash

That's it! You should see your SWF load and display the text Hello world!. If something along the way didn't work, take some time to review the chapter to see where things went wrong.

Making changes
You have been reading a chapter from
Haxe Game Development Essentials
Published in: Nov 2015
Publisher:
ISBN-13: 9781785289781
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image