Skip to content

Quick Guide

moly edited this page Apr 21, 2013 · 4 revisions

##Assets

To make the assets available to the game, we have to put them in the Android project's assets folder. The desktop project has a link to that assets folder, so we only need to store the assets once.

Assets are loaded by providing a path to the file. For example, if your assets folder contained a music track named "music.mp3", you would play it in flixel-gdx like this:

FlxG.playMusic("music.mp3", 1.0f);

You can create additional folders inside the assets folder, and access assets within them like so:

text.setFormat("fonts/comicsans.ttf", 24);

###Texture Packing

For best performance, it is highly recommended that you pack all your images together into what is known as a texture atlas. To help with this there is a tool available called TexturePacker. You can download the latest version from here. To create a texture atlas from your image assets:

  • Place all the images you wish to pack into an empty folder on your computer.
  • Run the texture packer tool.
  • Click "New Pack" and name it whatever you like.
  • Set the input directory to the folder where you placed your images.
  • Set the output directory somewhere safe.
  • Click "Pack selected".

Check your output folder. If everything was successful you should now have two files; a pack file "something.pack" and the atlas "something.png". The pack file is just a text file that lists each image's name and where it is stored in the atlas. Copy these files into the assets folder in the android project.

Note - After copying, you may have to refresh your Android project in Eclipse before the assets show. To do this, right click on the project and select "Refresh".

###Loading Packed Images

Packed images in flixel-gdx are accessed using a special notation. You provide the path to the pack file, a colon, and then the name of the image without its extension. For example, say we have packed two images called "player.png" and "coin.png" into an atlas and generated a pack file called "mygame.pack". You would access the images like so:

FlxSprite player = new FlxSprite(0, 0, "mygame.pack:player");
FlxSprite coin = new FlxSprite(50, 0, "mygame.pack:coin");

###Loading Text Files

There is a new function to load a text file from the assets folder.

String level1 = FlxG.loadString("level1.txt");

##Other Changes

###Properties

Java does not have getters and setters in the same way that AS3 does. This means that some properties have had to be renamed, for example:

player.facing = FlxSprite.LEFT;

is now:

player.setFacing(FlxSprite.LEFT);

If you can't seem to find a property, check to make sure it hasn't been renamed.

###Debugging

To enable debugging in flixel-gdx, simply set FlxG.debug to true anywhere in your application. When in debug mode, you can turn on visual debugging by pressing the F2 key.

To output information to the console (like trace in Flash) we recommend using FlxG.log(). This will output to the console when running on desktop, and to logcat when running on Android.

###Determining Platform

FlxG.mobile will automatically be set to true when run on a mobile device.

##Where To Find Examples

https://github.com/flixel-gdx/flixel-gdx-examples