Book Image

Learning AndEngine

By : Martin Varga
Book Image

Learning AndEngine

By: Martin Varga

Overview of this book

AndEngine is a very popular open source OpenGL (open graphics library) Android game engine, used to create mobile games quickly while maintaining the ability to fully customize them. This book will guide you through the whole development process of creating a mobile game for the Android platform using one of the most popular and easy-to-use game engines available today. Beginning with the very basics, you will learn how to install AndEngine, gather graphics, add sound and music assets, and design game rules. You will first design an example game and enhance it by adding various features over the course of the book. Each chapter adds more colors, enhances the game, and takes it to the next level. You will also learn how to work with Box2D, a popular 2D physics engine that forms an integral part of some of the most successful mobile games. By the end of the book, you will be able to create a complete, interactive, and fully featured mobile game for Android and publish it to Google Play.
Table of Contents (19 chapters)
Learning AndEngine
About the Author
About the Reviewers


Android has become the number one platform for mobile phones and tablets, and its popularity is still rising. Mobile game markets have become a great place for both professionals and indie game developers to present their games.

AndEngine was created by Nicolas Gramlich to ease the development of 2D games for Android devices. Since the beginning, AndEngine helped to create many successful games such as Traktor Digger, Construction City, and Bad Roads.

AndEngine is a full-featured open source engine. Its advantage is its simplicity. It is complete and makes creating any 2D game possible, and yet it is still easy to use. Moreover, AndEngine lets programmers use any part of the underlying Android SDK with no limitations.

Learning AndEngine is meant to teach the basics of AndEngine. It's a step-by-step guide to creating a simple game. Through the tutorial, all the basic features of AndEngine are presented in a concise way, making it easy to follow. The book starts with the installation of the required software, making a blueprint of the game, and follows with gradually adding features to the game as the readers learn them. Finally, a game is polished and released for a beta test in the most popular Android application store, the Google Play store.

The AndEngine source code exists in three versions. This book deals with the latest and most commonly used branch called the GLES2—AnchorCenter branch. It uses a newer graphics library, and it is stable and complete.

What this book covers

Chapter 1, Setting Up an AndEngine Project, introduces AndEngine and guides you through the installation of all the necessary software. At the end of the chapter, an empty AndEngine skeleton application is created.

Chapter 2, Game Concept and Assets, introduces the idea of the game that will be created. It begins with outlining the game rules, followed by gathering the game assets and scene diagram, and ends with a completed blueprint for the game.

Chapter 3, From Assets to Entities, explains loading the assets into memory and how to use them in a game. It shows a basic way to display an image on the screen by creating a game entity. It also explains the basic terms and different ways of storing images in memory, considering memory and quality requirements.

Chapter 4, HUD and Text Display, deals with loading fonts, national alphabets, and outputting text. It also explains heads-up display (HUD) and its usage in a game. The way to store characters and most common problems associated with it are explained as well.

Chapter 5, Basic Interactions, teaches you about basic animation and controls in AndEngine. Accelerometer and touchscreen are introduced along with collision detection. In this chapter, the game becomes interactive.

Chapter 6, Physics, introduces the AndEngine Box2D extension that takes care of physics simulation. Accelerometer readings are combined with procedural animation governed by the physics engine to create a better way of controlling the main character.

Chapter 7, Detecting Collisions and Reacting to Events, adds more interactivity and uses the physics engine's optimized collision detection. Game events are created and handled and playing sounds is explained too.

Chapter 8, Advanced Physics, introduces concepts that are not necessary for the game, but nevertheless important. Multiple fixture bodies that can make simulation more precise and realistic are introduced. Collision filtering and its use as an optimization technique is described. Finally, all physics engine joints are listed and explained.

Chapter 9, Adding a Menu and Splash Scene, describes exactly what the title suggests. In this chapter, a splash scene that is shown at the start of the game is added and a way to load resources in the background is described. Also, a simple menu scene is added as an entry point to the game.

Chapter 10, Polishing the Game, explores a few ways to polish the game and make it more interesting by adding music, more animations, and some special effects. A standalone fire and smoke particle engine example is created.

Chapter 11, Testing, Publishing, and What's Next, shares insights about joining a community of developers, user testing, debugging, and publishing the game.

What you need for this book

Learning AndEngine is meant for complete beginners in Android game development, but you should know the fundamentals of Java programming. Having some knowledge of the Android platform is beneficial but not required and no knowledge of AndEngine is expected.

All the required software applications are open source and can be obtained for free from the Internet. Therefore, an Internet connection is required. The first chapter of the book helps you download the software and set your environment.

To follow the tutorial in this book, you should own an Android phone or tablet and a PC or a Mac that is able to run the Eclipse IDE and Android SDK. The examples can be run on an Android emulator but it is not recommended.

Who this book is for

If you are an aspiring game developer who is looking for a quick way into the Android game developer world, this is the book for you! This book is most beneficial for those who haven't created any games yet. More advanced users who have made a game in AndEngine already will most likely find the book to be very basic.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The versionName value will be displayed in the store listing."

A block of code is set as follows:

public void populate() {
  engine.enableAccelerationSensor(activity, this);

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

if (player.isDead()) {
  if (score > activity.getHiScore()) {

Any command-line input or output is written as follows:

adb install LearningAndEngine.apk

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "The option is located in the main button bar and in the Window menu."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from:


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.