Project Setup

Thomas Weston edited this page Feb 23, 2014 · 12 revisions

Note - This guide assumes you already have Eclipse and the Android SDK installed and working on your computer. If not, follow this first: http://developer.android.com/sdk/index.html

##Using the GUI

flixel-gdx now comes with a gui utility to help simplify the setup process. We would recommend this option for most users.

###Setup

  1. Download the latest "setup-ui" jar here: http://flixel-gdx.org/dist/setup-gui.jar
  2. Run the jar by double clicking on it.
  3. Specify your projects properties using the text fields.
  4. Click "Open the generation screen".
  5. Click "Launch" to start downloading the required libraries and automatically set up your projects.
  6. Open Eclipse and import the generated projects into your workspace:
  • File -> Import -> Existing Projects into Workspace
  • Click "Browse", select the folder containing the generated projects.
  • Make sure all the projects are checked, then click "Finish"

###Running Your Application

  • Desktop: Right click the desktop project, Run As -> Java Application. Select the desktop starter class (e.g. Main.java).
  • Android: make sure you have either a device connected or an emulator installed. Right click your Android project, Run As -> Android Application.

##From Git

If you want to be able to edit the source code of flixel-gdx, you will need to checkout the most recent revision from the Git repository and set up your project manually.

  1. Use Git to checkout the latest revision from our github page, or download the project as a zip file.
  2. Run fetch.xml (located in the root directory) to fetch the required dependencies.
  3. Once done, open Eclipse and import the projects into your workspace:
  • File -> Import -> Existing Projects into Workspace
  • Click "Browse", select the folder containing the projects
  • Make sure all the projects are checked, then click "Finish"

Note: Java 1.7 is currently problematic in combination with Android. Please make sure your project uses Java 1.6

###Core Project Setup

  1. Create a new Java project in Eclipse: File -> New -> Project -> Java Project. Give it a name and click Finish.
  2. In Eclipse, right click the project -> Properties -> Java Build Path -> Projects -> Add... -> select flixel-core and click OK.

###Desktop Project Setup

  1. Create a new Java project in Eclipse: File -> New -> Project -> Java Project. Name it appropriately (eg, "gamename-desktop") and click Finish.
  2. In Eclipse, right click the project -> Properties -> Java Build Path -> Projects -> Add... -> select flixel-desktop AND your core project and click OK.

###Android Project Setup

  1. Create a new Android project in Eclipse: File -> New -> Project -> Android Project. Name it appropriately (eg, "gamename-android"). For build target, check "Android 1.5". Specify a package name (eg, "com.gamename"). Next to "Create Activity" enter "AndroidGame". Click Finish.
  2. In Eclipse, right click the project -> Properties -> Android. In the Library section click on Add..., select flixel-android and click OK.
  3. Still in Properties, go to Java Build Path -> Projects -> Add... -> check your core project and click OK.
  4. Click the Order and Export tab, check your core project.

###GWT Project Setup

You need to install GWT Plugin and SDK for Eclipse: https://developers.google.com/eclipse/docs/download

  1. Create a new GWT project in Eclipse: File -> New -> Project -> Web Application Project. In the setup menu uncheck “Use Google App Engine” and “Generate project sample code”. Give it a packname e.g. “com.yourname.flixelgame”.
  2. In Eclipse, right click the project -> Properties -> Java Build Path -> Projects -> Add… -> select flixel-html5 AND your core project and click OK.

###Asset Folder Setup

The Android project has a subfolder named assets, which was created automatically. Files available to the Android application must be placed here. This is problematic, because these same files must be available to the desktop application. Rather than maintain two copies of all the files, the desktop project can be configured to find the assets in the Android project:

  1. In Eclipse, right click your desktop project -> Properties -> Java Build Path -> Source tab.
  2. Click Link Source, Browse, select the "assets" folder from your Android project and click OK.
  3. Specify "assets" for the folder name and click Finish then OK.

Note: If your desktop and Android projects are in the same parent folder, you can use "PARENT-1-PROJECT_LOC/gamename-android/assets" for the location of the linked assets folder, where "gamename-android" is the name of your Android project. This is better than a hardcoded path if you plan on sharing your projects with others.

###Creating a Game

  1. In your core project, create a new class (right click the project -> New -> Class). Name it PlayState and specify a package. Set its superclass to FlxState and click OK.
  2. Create another new class. Name it Game, set its superclass to FlxGame and click OK.
  3. Add a constructor to the Game class so that it looks like this:
package com.yourname.flixelgame;

import org.flixel.FlxGame;

public class Game extends FlxGame
{
    public Game()
    {
        super(400, 240, PlayState.class, 2);
    }
}

###Running the Game on the Desktop

  1. Right click the desktop project -> New -> Class. Name it DesktopGame and specify a package (eg, "com.gamename"). Click OK. Make the class look like this:
package com.yourname.flixelgame;

import org.flixel.FlxDesktopApplication;

public class Main
{
    public static void main(String[] args) 
    {
        new FlxDesktopApplication(new FlixelGame(), 800, 480);
    }
}
  1. To run the game on the desktop, right click the project -> Debug As -> Java Application. You should get a black window.

###Running the Game on Android

  1. Open the AndroidGame class in the Android project that was automatically created and make it look like this:
package com.yourname.flixelgame;

import org.flixel.FlxAndroidApplication;

public class AndroidGame extends FlxAndroidApplication 
{
    public AndroidGame()
    {
        super(new Game());
    }
}
  1. To run the game on Android, right click the project -> Debug As -> Android Application. The screen will turn black, since the game doesn't yet do anything. If any errors occur running the application, they show up in the Logcat view, which can be seen by clicking Window -> Show View -> Other -> Android -> Logcat.

###Running the Game on GWT

  1. Right click in the GWT project -> new Class. Name it GameStarter and put it in the com.yourname.flixelgame package. Click OK. Make the class look like this:
package com.yourname.flixelgame;

import org.flixel.FlxGame;
import org.flixel.client.FlxHtml5Application;

public class GameStarter extends FlxHtml5Application
{

	public GameStarter()
	{
		super(new FlixelGame(), 800, 400);
	}
}
  1. Right click in GWT project -> File. Name it gamestarter_html5.gwt.xml. Put it in com.yourname. Make the xml look like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module rename-to="com.yourname.gamestarter_html5">
	<!-- inheritances. If you use 3rd parties libaries, you need to include them here -->
	<inherits name="com.yourname.flixelgame" />
	<inherits name="org.flixel.flixel_html5" />
	
	<!-- Your main class -->
	<entry-point class='com.yourname.flixelgame.GameStarter' />
	
	<!-- Assets folder, which is in your Android project -->
	<set-configuration-property name="gdx.assetpath" value="../gamename-android/assets" />
	
	<!-- The PlayState is one of your class that needs to be included in the reflection -->
	<!-- If you've other classes that uses Reflection, include them here -->
	<extend-configuration-property name="gdx.reflect.include" value="com.yourname.flixelgame.PlayState" />
</module>

For every inheritance you need a .gwt.xml file. In this example there are two inheritances:

<inherits name=”com.yourname.flixelgame” />
<inherits name=”org.flixel.flixel_html5” />

flixel_html5.gwt.xml is already created. You can find it in flixel-html5/src/org/flixel. For your own project you need to create it by yourself. Right click the core project -> File. Name it flixelgame_core.gwt.xml. Put it in the com.yourname package. Make the xml look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN"
  "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module>
	<source path="flixelgame"/>
</module>

The source path is the path to the classes. We put the flixelgame_core.gwt.xml file in com.yourname, this means the classes will be in flixelgame folder.

  1. To run the game, right click the project -> Run as -> Web Application. In the Development Mode tab there will be a link. Copy this link and paste in Chrome. If Chrome asks for the GWT Developer Plugin, install it. After this your game will run in the browser. You’ll notice that the game will run very slow, because it’s in debug mode.

####Compile GWT project Compile the project, right click the project -> Google -> GWT Compile -> click on Compile. Default the compiled files will be in the war folder of the GWT project. Put the files on a server. Navigate to the html file. The game should run at full speed.

#####GWT Compile Tips To speed up the compile time you optimize the *gwt.xml file file as follows:

<set-property name="user.agent" value="safari"/>

This will only compile for browsers with the user agent Safari (Safari and Chrome). Available user agents can be found here: https://gwt.googlesource.com/gwt/+/master/user/src/com/google/gwt/useragent/UserAgent.gwt.xml

In GWT Compile you can add the following arguments:

-draftCompile Enable faster, but less-optimized, compilations.
-localWorkers The number of local workers to use when compiling permutations. If you got 4 CPU, -localWorkers 4.
-XdisableCastChecking EXPERIMENTAL: Disables run-time checking of cast operations
-Xmx1024m Tweak the memory that will be available when compiling.

Take a look at the screenshot for an example:
GWT Compile Arguments

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.