Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
AndEngine for Android Game Development Cookbook

You're reading from   AndEngine for Android Game Development Cookbook AndEngine is a simple but powerful 2D game engine that's ideal for developers who want to create mobile games. This cookbook will get you up to speed with the latest features and techniques quickly and practically.

Arrow left icon
Product type Paperback
Published in Jan 2013
Publisher Packt
ISBN-13 9781849518987
Length 380 pages
Edition 1st Edition
Arrow right icon
Authors (3):
Arrow left icon
Brian Boyles Brian Boyles
Author Profile Icon Brian Boyles
Brian Boyles
Nicolas Gramlich Nicolas Gramlich
Author Profile Icon Nicolas Gramlich
Nicolas Gramlich
JAYME SCHROEDER JAYME SCHROEDER
Author Profile Icon JAYME SCHROEDER
JAYME SCHROEDER
Arrow right icon
View More author details
Toc

Table of Contents (18) Chapters Close

AndEngine for Android Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. AndEngine Game Structure FREE CHAPTER 2. Working with Entities 3. Designing Your Menu 4. Working with Cameras 5. Scene and Layer Management 6. Applications of Physics 7. Working with Update Handlers 8. Maximizing Performance 9. AndEngine Extensions Overview 10. Getting More From AndEngine Source Code for MagneTank Index

Handling the removal of an entity from the game


Detaching entities within an update handler can occasionally throw an IndexOutOfBoundsException exception, because the entity is removed in the middle of an engine update. To avoid that exception, we create a Runnable parameter that is run last on the update thread, after all other updating has occurred. In this recipe, we will safely remove an entity from the game by using the BaseGameActivity class' runOnUpdateThread() method.

Getting ready...

Create a new class named HandlingRemovalOfEntityActivity that extends BaseGameActivity. We will use this class to learn how to safely remove an entity from an update handler.

How to do it...

Follow these steps to see how we can remove an entity from its parent without throwing an exception:

  1. Insert the following definitions into the HandlingRemovalOfEntityActivity class:

    public static int cameraWidth = 800;
    public static int cameraHeight = 480;
    public Scene mScene;
    public Rectangle spinningRect;
    public float...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime