The iPhone has taken the world by storm, but with the backing of Google the Android platform is picking up steam and has a bright future ahead of it. But while there are dozens of tools to create games on the iPhone, Android has only a few examples showing how to make a game, and I could not find any decent engines or middleware on which to build a game on Android.
Flixel is a game engine for Flash that I have used quite a bit lately, and after my experiences porting it to Silverlight I felt confident that Flixel would make a great platform for Android on which to make games. This tutorial series will show you how to make your own simple platform game on Android using the ported Flixel engine.
Step 1
Download a copy of Eclipse from here, and then download both the Android SDK and the Eclipse plugins from the Android site here. You can find step by step instructions on how to do this on the Android developer site.
Step 2
Start Eclipse once the Android plugins for Eclipse have been installed. Open Window->Preferences.
In the Android section browse to the location where you extracted the Andorid SDK and click the Apply button. The SDK should then be listed.

Step 3
Create a new Android Application.
If you get the error below make sure you have completed step 2 successfully.
Fill out the first New Android Project screen like below. You can change the names of the application and packages as long as these changes are made to the rest of the classes where appropriate.
There is no need to create a Test Project, so do not tick Create a Test Project.
Step 4
Extract the contents of the Android Flixel SDK into your project folder. This will extract a number of standard mp3s and images, along with the Flixel source files (under the org.flixel and flash packages).
Step 5
Create a new class called MenuState in the org.myname.flixeldemo package. It will extend the FlxState class.
In Flixel the various states in a game (like the main menu, the game itself, a high scrore screen etc) are represented by classes that extend the FlxState class. As the player progressed through the game these FlxState classes are created and destroyed to present the different aspects of the game.
Add the following code to the MenuState class. Here we are going to display a text field just so we have something on the screen.
package org.myname.flixeldemo;
import org.flixel.*;
public class MenuState extends FlxState
{
public MenuState()
{
super();
add(new FlxText(10, 10, 100, "Hello World!"));
}
}
Step 6
Create a new class called GameView in the org.myname.flixeldemo package. It will extend the FlxGameView class.
Unlike a Flash game made with Flixel, where graphical objects can be added directly to the screen, Andoid has a fairly complicated system for allowing continuously running applications (like games) to draw to the screen. You have to create a thread to contain the render loop and then pass in events like key presses to the thread while maintaining thread safety. You can view the Lunar Landing demo for an example of how this works. Fortunately the FlxGameView class hides all of the underlying logic required to implement the render loop.
Add the following code to the GameView class. Here we pass a new FlxGame, which is the root of every Flixel game, to the FlxGameView constructor. The FlxGame constructor takes a few parameters like the context (which allows Flixel to create graphics and sound resources), the initial state class information of the game (which will be the MenuState we created above) and the R class information (the R object is created automatically to contain references to the graphics and sound resources).
package org.myname.flixeldemo;
import org.flixel.FlxGame;
import org.flixel.FlxGameView;
import android.content.Context;
import android.util.AttributeSet;
public class GameView extends FlxGameView
{
public GameView(Context context, AttributeSet attrs)
{
super(
new FlxGame(320, 455, MenuState.class, context, R.class),
context,
attrs
);
}
}
Step 7
In order to display the GameView object we just created we need to modify the main.xml file under the res/layout folder. Change it so it looks like the image below. This will cause the FlixelDemo Activity, created when the project was created, to display the GameView object.
Step 8
Add the line of code
requestWindowFeature(Window.FEATURE_NO_TITLE);
to the FlixelDemo class like the screen shot below. This will remove the title bar from the application.
Step 9
To test the game we need to setup a Android elmulator. Click Window->Android SDK and AVD Manager.
Click the New button. Add in the details for the AVD (Android Virtual Device) like the screenshot below. Click Create AVD.
You should now have a Virtual Device listed.
Step 10
Now we can run the demo. Click the Run button on the toolbar.
Select Android Application and click OK.
The AVD will start up. This can take some time initially, so be patient.
Congratulations – you have created you first Android game.
Popularity: 1% [?]
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
RSS Feed
Twitter

февруари 3rd, 2010
admin 


















Posted in 

THANKS!! Worked first time…
EXCELLENT!!!
Not familiar with flixel on Flash etc.. but will give it a try.
Any more complex examples would be appreciated..
This technology is highly popular these days due to the fact that „Flash Video On Websites“ Tool requires almost no special technical knowledge or resources from the user’s side in order to create Flash-Videos. Now that you know more about this technology it is advised to watch it in action and experience how it easily enables you to further promote your online business.
I Really like what you have done with your blog! Will you please check out my site? It is new and i would like to show it off! The site is http://www.publicdomainpayday.com
My kids were constantly asking me to buy them new video games. It was really expansive until I discovered free online games. Free online games are fun and eductional.
Great Posts……
I saw this really good post today on……
The lack of 3G coverage is really frustrating. I live in Wyoming, so I’ve come to anticipate that we’re going to be way behind the more populated areas. Even So, the fact that Verizon and Sprint are offering 3G and I’m still stuck with EDGE is truly beginning to annoy. I’ve been very happy with the service that T-Mobile has provided me with over the years, but if they go along to discount their customers out here I’ll seriously deliberate swapping companies.
I saw this really cool post today……
[..]I saw this post today on another blog that impressed me[..]…