In this series I will tell you how to use one of my favorite Android 2D Game Engines, AndEngine. We will go step by step through the processes, starting at simply getting the code, continuing with drawing sprites, using cameras, physics and so on.
AndEngine was started by Nicolas Gramlich as part of his Bachelor’s thesis in the beginning of 2010. It is an engine that provides lots of powerful features while hiding more advanced things like Open GL calls from the developer. It provides lots of extensions like a Robotium extension, a Box2D extension, which is mostly written and maintained by badlogicgames‘ Mario Zechner for his libGDX-project, a SVG extension or a TMX tiled maps extension.
It has been used in various featured games like Greedy Spiders, Noogra Nuts or Zynga’s Dream Zoo.
Let’s get started.
Getting the code
At the very beginning you’ll need to download the most recent version of AndEngine. To do that, open your console, go to the directory of your choice and do a git clone of the engine by typing
git clone git://github.com/nicolasgramlich/AndEngine.git
That’s all. You now have a powerful game engine, ready to be used on your computer or mobile device.
Now here’s a story: When AndEngine was written, the author had to make a choice: did he want to write lots of useful code or lots of useful documentation? He chose the more fun part and that’s why AndEngine provides little to no documentation, which is one of its most frequent points of criticism. However, the source is all open, you can read it, change it, do whatever you like with it. There are the AndEngine forums and Nicolas tries to write the code in a way that it’s documenting itself.
In order to provide the developers an idea of what AndEngine can do, the AndEngine samples were created. You can get them by also cloning the git repository:
git clone git://github.com/nicolasgramlich/AndEngineExamples.git
As you can now see there are a lot of dependencies to the different extensions. Go ahead and clone them:
git clone git://github.com/nicolasgramlich/AndEngineAugmentedRealityExtension.git
git clone git://github.com/nicolasgramlich/AndEngineLiveWallpaperExtension.git
git clone git://github.com/nicolasgramlich/AndEngineMODPlayerExtension.git
git clone https://github.com/nicolasgramlich/AndEngineMultiplayerExtension
git clone https://github.com/nicolasgramlich/AndEnginePhysicsBox2DExtension
git clone https://github.com/nicolasgramlich/AndEngineSVGTextureRegionExtension
git clone https://github.com/nicolasgramlich/AndEngineTexturePackerExtension
git clone https://github.com/nicolasgramlich/AndEngineTMXTiledMapExtension
Now you have a lot of code. Import them into your IDE of choice. Your workspace should now look something like this:
Let’s start a look at the examples. Connect your device or start an emulator with GPU emulation and run the AndEngineExamples on it.
AndEngine physics example
What you will find is an overview over AndEngine’s many features.
There are two important branches of AndEngine: The GLES2-branch and the GLES2-AnchorCenter branch. Since the latter will become the main branch soon, it is recommended to pull its code too. To do so, just go into each of your AndEngine-projects using your shell and execute
git pull origin GLES2-AnchorCenter
You might want to switch to this branch now by executing
git checkout -b GLES2-AnchorCenter origin/GLES2-AnchorCenter
Now take your time to play, take a look into the code and look forward to the next part of this series in which we will go through the basic parts of the engine.
If you are having problems compiling any of AndEngine’s code or issues cloning the repositories, please post a comment.