Greetings!

The main purpose of this website is to support Android indie game developers with tutorials, reviews and promotion of their games. The main difficulty for the developers is not to make the game, but to get exposure. To get it out there. If you find anything useful here, please spread the word. Like my page on Facebook, follow me on Google+ or Twitter. Thank you!

Google+ Facebook Twitter

× close

Sunday 8 September 2013

AndEngine Tutorial - Extensions and Examples

This tutorial is part of AndEngine basics.


<< List of all tutorials

AndEngine has no documentation - that's a fact. However Nicolas Gramlich created an AndEngine application covering most of the AndEngine features and extensions as well. You can check the app in Google Play store to see the capabilities right now. And you can also download source codes of this app from Nicolas' GitHub. If it won't be enough, this book about AndEngine covers all of the basics as well.

To compile and run the examples yourself, you need to download and setup the extensions referenced in the examples. Notice that there are more extensions than those referenced by examples and also Nicolas' GitHub contains more of his projects that relate to AndEngine. To make it easier, let's work only with the extensions needed for AndEngine examples project.

There are many useful extensions for AndEngine like Physics Box2D extension or Live Wallpaper extension. These exists as separate Android Library projects. This tutorial is about how to setup the most popular extensions along with the Examples project. Note that this tutorial was written on 9th September 2013 and if something changes in the GitHub repositories, it might get outdated. Please let me know if that happens by sending mail to android@kul.is.

Important: I have changed the previous tutorial Getting Started. If you have followed it before 8th September, please note that I have renamed the AndEngine-GLES2-AnchorCenter imported project to simply AndEngine. It's the correct way and it makes things easier later. Check the tutorial and recreate the import step.


Download and import all required AndEngine projects

Please start with my first tutorial: Getting Started, if you haven't already setup basic AndEngine. Next download the following projects by clicking on Download Zip button. Make sure you are downloading GLES2 - AnchorCenter branch where applicable. Using Git directly is better, but it's a more advanced topic.

The tutorial shows you how to download everything from original Nicolas' Github repositories. If you want to skip the later part of the tutorial, where you fix bugs in the code, you can download my own version from GitHub. Simple change "nicolasgramlich" to "sm4" in the url: https://github.com/sm4/AndEngine/tree/GLES2-AnchorCenter

Check my other tutorial on GitHub to see the alternative way to download the sources.



Projects to download:


Unpack all the projects in your workspace where you have already unpacked and imported AndEngine project. Rename all directories in order to remove the "-master", "-GLES2" or "-GLES2-AnchorCenter" suffix. These are created by GitHub  - if you use Git, you won't see directories named "GLES2-AnchorCenter". I will explain in the next tutorial the "GitHub" way of importing all projects

Start Eclipse and select: File -> Import... -> Existing Projects into Workspace. Click Browse to select your workspace directory for Select root directory. This is what you should see now. Of course the AndEngine base project must be there already imported.



Press Finish and you should get a message similar to this in console view:

[2013-09-08 22:48:16 - AndEngineAugmentedRealityExtension] Unable to resolve target 'android-15'
[2013-09-08 22:48:16 - AndEngineScriptingExtension] Unable to resolve target 'android-15'
[2013-09-08 22:48:16 - AndEngineSVGTextureRegionExtension] Unable to resolve target 'android-15'
[2013-09-08 22:48:16 - AndEnginePhysicsBox2DExtension] Unable to resolve target 'android-17'
[2013-09-08 22:48:16 - AndEngineMultiplayerExtension] Unable to resolve target 'android-17'
[2013-09-08 22:48:16 - AndEngineExamples] Unable to resolve target 'android-15'
[2013-09-08 22:48:16 - AndEngineTMXTiledMapExtension] Unable to resolve target 'android-15'
[2013-09-08 22:48:16 - AndEngineMODPlayerExtension] Unable to resolve target 'android-15'
[2013-09-08 22:48:16 - AndEngineLiveWallpaperExtension] Unable to resolve target 'android-15'
[2013-09-08 22:48:16 - AndEngineCocosBuilderExtensionCCRotatingSpriteExtension] Unable to resolve target 'android-15'
[2013-09-08 22:48:16 - AndEngineCocosBuilderExtension] Unable to resolve target 'android-15'

Now that was expected. You have to fix the Android SDK settings for each of the projects.

Fix the projects setup


For each project, right click on it, select Properties and choose Android. There should be just one option to select (Android 4.3). Check the Android 4.3 option. Do this for all the extension and the Examples project. If you have followed the tutorial step-by-step this is what you should see in the Examples project properties:



Select Project -> Clean -> Clean all projects from Eclipse main menu. You will notice that some projects still contain bugs and you are not able to compile the AndEngineExamples project before fixing them.

SVG Extension problem

When using somebody's projects, especially open source and free, you must count with such issues. Let's fix it:

The type SVGBaseBitmapTextureAtlasSource must implement the inherited abstract method IBitmapTextureAtlasSource.onLoadBitmap(Bitmap$Config, boolean) in SVGBaseBitmapTextureAtlasSource.java

Open SVGBaseBitmapTextureAtlasSource.java (Ctrl+Shift+R) and  use the Eclipse quick fix: Add unimplemented methods. That's it. The problem exists, because SVG extension doesn't have the AnchorCenter version.

Scripting Extension problems

There are few ways how to deal with this - you can remove the reference from Examples and then fix the problem that arise from there. Or you can try to fix each problem in this extension:

1) Use Search -> File in Eclipse main menu and replace

import org.andengine.util.color.Color;

with


import org.andengine.util.adt.color.Color;

2) remove class RectangularShapeProxy - it's not used in AnchorCenter version.

AndEngine Examples problems

Finally you can solve the AndEngine examples project problems - most of them are just renamed packages. Use the mass search & replace in files and replace the following in the examples project.

Search Replace
import org.andengine.extension.multiplayer.protocol import org.andengine.extension.multiplayer
import org.andengine.extension.multiplayer.exception.BluetoothException; import org.andengine.util.exception.BluetoothException;
import org.andengine.entity.particle.modifier.ExpireParticleInitializer; import org.andengine.entity.particle.initializer.ExpireParticleInitializer;
import org.andengine.extension.multiplayer.util.IPUtils; import org.andengine.util.IPUtils;
import org.andengine.extension.multiplayer.util.WifiUtils; import org.andengine.util.WifiUtils;
if(!AndEngine.isDeviceSupported()) { if(!AndEngine.isDeviceSupported(this)) {


Make sure you check where and what are you replacing. After you finish this, there will still be errors left. Eclipse will point you to the classes where wrong Exception handling occurs. Use "Problems" view to see all errors in all your projects in the workspace.

These are easy to correct using this dirty fix: Simply change all catches in the problematic try-catch blocks to "Exception" only. And that's it. There is no easy search and replace pattern for this.

Save all files and clean all projects if there are still any errors. If you followed this tutorial, you should have error free setup in your Eclipse. If not, maybe you forgot something. If you can't resolve it yourself, you can try sending me an email to android@kul.is.

Run the examples

Right click on the AndroidExamples project and select Run As -> Android Application. If the device selector pops up, select your Android device. Enjoy!

Alternative GitHub repositories

Some members of the AndEngine community already fixed these problems and maintain their own repositories. They usually fix some errors along the way too, but sometimes their version is not the newest. You can go to forums and search for yourself. Some notable examples of such repositories are:


I haven't used them though. Or you can use my repositories. My version of AndEngine has some bugs fixed.

Further reading

You can see the list of books about Android Game Development for further reading, not just about AndEngine but game development in general.
Martin Varga is a Czech software developer who likes pygmy owls (hence Kulíš), running, ramen, travelling and living in foreign countries. He is also known as smartus or sm4 on the internet (read as smartass, but there are too many of them). He currently tries to make games in AndEngine like Mr. Dandelion's Adventures and hangs around a lot at the AndEngine forums.