Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
AndEngine for Android Game Development Cookbook
AndEngine for Android Game Development Cookbook

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
Profile Icon JAYME SCHROEDER Profile Icon Brian Boyles
Arrow right icon
AU$24.99 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (25 Ratings)
Paperback Jan 2013 380 pages 1st Edition
eBook
AU$36.99 AU$53.99
Paperback
AU$67.99
Subscription
Free Trial
Renews at AU$24.99p/m
Arrow left icon
Profile Icon JAYME SCHROEDER Profile Icon Brian Boyles
Arrow right icon
AU$24.99 per month
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (25 Ratings)
Paperback Jan 2013 380 pages 1st Edition
eBook
AU$36.99 AU$53.99
Paperback
AU$67.99
Subscription
Free Trial
Renews at AU$24.99p/m
eBook
AU$36.99 AU$53.99
Paperback
AU$67.99
Subscription
Free Trial
Renews at AU$24.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $24.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

AndEngine for Android Game Development Cookbook

Chapter 2. Working with Entities

In this chapter, we're going to start getting into displaying objects on the screen and various ways we can work with these objects. The topics include:

  • Understanding AndEngine entities

  • Applying primitives to a layer

  • Bringing a scene to life with sprites

  • Applying text to a layer

  • Using relative rotation

  • Overriding the onManagedUpdate method

  • Using modifiers and entity modifiers

  • Working with particle systems

Introduction


In this chapter, we're going to start working with all of the wonderful entities included in AndEngine. Entities provide us with a base foundation that every object displayed within our game world will rely on, be it the score text, the background image, the player's character, buttons, and everything else. One way to think of this is that any object in our game which has the ability to be placed, via AndEngine's coordinate system, is an entity at its most basic level. In this chapter, we're going to start working with Entity objects and many of its subtypes in order to allow us to make the most out of them in our own games.

Understanding AndEngine entities


The AndEngine game engine follows the entity-component model. The entity-component design is very common in a lot of game engines today, and for a good reason. It's easy to use, it's modular, and it is extremely useful in the sense that all game objects can be traced back to the single, most basic Entity object. The entity-component model can be thought of as the "entity" portion referring to the most basic level of the game engine's object system. The Entity class handles only the most basic data that our game objects rely on, such as position, rotation, color, attaching and detaching to and from the scene, and more. The "component" portion refers to the modular subtypes of the Entity class, such as the Scene, Sprite, Text, ParticleSystem, Rectangle, Mesh, and every other object which can be placed within our game. The components are meant to handle more specific tasks, while the entity is meant to act as a base foundation that all components will rely on...

Applying primitives to a layer


AndEngine's primitive types include Line, Rectangle, Mesh, and Gradient objects. In this topic, we're going to focus on the Mesh class. Meshes are useful for creating more complex shapes in our games which can have an unlimited amount of uses. In this recipe, we're going to use Mesh objects to build a house as seen in the the following figure:

Getting ready…

Please refer to the class named ApplyingPrimitives in the code bundle.

How to do it…

In order to create a Mesh object, we need to do a little bit more work than what's required for a typical Rectangle or Line object. Working with Mesh objects is useful for a number of reasons. They allow us to strengthen our skills as far as the OpenGL coordinate system goes, we can create oddly-shaped primitives, and we are able to alter individual vertice positions, which can be useful for certain types of animation.

  1. The first step involved in creating Mesh objects is to create our buffer data which is used to specify the...

Bringing a scene to life with sprites


Here, we come to the topic which might be considered to be the most necessary aspect to creating any 2D game. Sprites allow us to display 2D images on our scene which can be used to display buttons, characters/avatars, environments and themes, backgrounds, and any other entity in our game which may require representation by means of an image file. In this recipe, we'll be covering the various aspects of AndEngine's Sprite entities which will give us the information we need to continue to work with Sprite objects later on in more complex situations.

Getting ready…

Before we dive into the inner-workings of how sprites are created, we need to understand how to create and manage AndEngine's BitmapTextureAtlas/BuildableBitmapTextureAtlas objects as well as the ITextureRegion object. For more information, please refer to the recipes, Working with different types of textures and Applying texture options in Chapter 1, AndEngine Game Structure.

Once these recipes...

Applying text to a layer


Text is an important part of game development as it can be used to dynamically display point systems, tutorials, descriptions, and more. AndEngine also allows us to create text styles which suit individual game types better by specifying customized Font objects. In this recipe, we're going to create a Text object, which updates itself with the current system time as well as correct its position every time the length of the string grows or shrinks. This will prepare us for the use of Text objects in cases where we need to display scores, time, and other non-specific dynamic string situations.

Getting ready…

Applying Text objects to our Scene object requires a working knowledge of AndEngine's font resources. Please perform the the recipe, Using AndEngine font resources in Chapter 1, Working with Entities, then proceed with the How to do it... section of this recipe. Refer to the class named ApplyingText in the code bundle for this recipe's activity in code.

How to do...

Using relative rotation


Rotating entities relative to the position of other entities in 2D space is a great function to know. The uses for relative rotation are limitless and always seems to be a "hot topic" for newer mobile game developers. One of the more prominent examples of this technique being used is in tower-defense games, which allows a tower's turret to aim towards the direction that an enemy, non-playable character is walking. In this recipe, we're going to introduce a method of rotating our Entity objects in order to point them in the direction of a given x/y position. The following image displays how we will create an arrow on the scene, which will automatically point to the position of the circle image, wherever it moves to:

Getting ready…

We'll need to include two images for this recipe; one named marble.png at 32 x 32 pixels in dimension and another named arrow.png at 31 pixels wide by 59 pixels high. The marble can be any image. We will simply drag this image around the scene...

Overriding the onManagedUpdate method


Overriding an Entity object's onManagedUpdate() method can be extremely useful in all types of situations. By doing so, we can allow our entities to execute code every time the entity is updated through the update thread, occuring many times per second unless the entity is set to ignore updates. There are so many possibilities including animating our entity, checking for collisions, producing timed events, and much more. Using our Entity objects's onManagedUpdate() method also saves us from having to create and register new timer handlers for time-based events for a single entity.

Getting ready…

This recipe requires basic knowledge of the Entity object in AndEngine. Please read through the entire recipe, Understanding AndEngine entities given in this chapter, then create a new empty AndEngine project with a BaseGameActivity class and refer to the class named OverridingUpdates in the code bundle.

How to do it…

In this recipe, we are creating two Rectangle...

Using modifiers and entity modifiers


AndEngine provides us with what are known as modifiers and entity modifiers. Through the use of these modifiers we can apply neat effects to our entities with great ease. These modifiers apply specific changes to an Entity object over a defined period of time, such as movement, scaling, rotation, and more. On top of that, we can include listeners and ease functions to entity modifiers for full control over how they work, making them some of the most powerful-to-use methods for applying certain types of animation to our Scene object in AndEngine.

Note

Before continuing, we should mention that a modifier and an entity modifier in AndEngine are two different objects. A modifier is meant to be applied directly to an entity, causing modifications to an entity's properties over time, such as scaling, movement, and rotation. An entity modifier on the other hand, is meant to act as a container for any number of modifiers, which handle the order in which a group...

Working with particle systems


Particle systems can provide our games with very attractive effects for many different events in our games, such as explosions, sparks, gore, rain, and much more. In this chapter, we're going to cover AndEngine's ParticleSystem classes which will be used to create customized particle effects that will suit our every need.

Getting ready…

This recipe requires basic knowledge of the Sprite object in AndEngine. Please read through the entire recipes, Working with different types of textures in Chapter 1, AndEngine Game Structure, as well as Understanding AndEngine entities given in this chapter. Next, create a new empty AndEngine project with a BaseGameActivity class and import the code from the WorkingWithParticles class in the code bundle.

How to do it…

In order to begin creating particle effects in AndEngine, we require a bare minimum of three objects. These objects include an ITextureRegion object which will represent the individual particles spawned, a ParticleSystem...

Left arrow icon Right arrow icon

Key benefits

  • Step by step detailed instructions and information on a number of AndEngine functions, including illustrations and diagrams for added support and results
  • Learn all about the various aspects of AndEngine with prime and practical examples, useful for bringing your ideas to life
  • Improve the performance of past and future game projects with a collection of useful optimization tips
  • Structure your applications in a manner that provides a smooth flow from splash screen to level selection, to game play

Description

AndEngine is a broad 2D game engine which allows game developers, both experienced and inexperienced, to develop games for the Android platform with ease. Don't be fooled by the simplicity, though. As easy as it is to “pick up and go,” AndEngine includes enough functionality to bring any type of 2D game world to life.The "AndEngine for Android Game Development Cookbook" contains all of the necessary information and examples in order to build the games as you imagine them. The book's recipes will walk you through the various aspects of game design with AndEngine and provides detailed instructions on how to achieve some of the most desirable effects for your games.The "AndEngine for Android Game Development Cookbook" begins with detailed information on some of the more useful structuring techniques in game design and general aspects of resource management. Continuing on, the book will begin to discuss AndEngine entities, including sprites, text, meshes, and more. Everything from positioning, to modifiers, and even tips on improving entity functionality with raw OpenGL capabilities. From here on, everything from applying physics to your game, working with multi-touch events and gestures, game optimization, and even an overview of the various AndEngine extensions will be covered.The book has a widerange of recipes, from saving and loading game data, applying parallax backgrounds to create a seemingly 3D world, relying on touch events to zoom the game camera, taking screen-shots of the device's screen, and performance optimization using object pools. If physics-based games are more interesting to you, there's also a list of recipes ranging from controlling the world forces and calculating forces applied to bodies, creating destructible objects, and even creating rag-dolls.Pong styled games were fun 35 years ago, but it is time to take your game to the next level with the AndEngine for Android Game Development Cookbook.

Who is this book for?

"AndEngine for Android Game Development Cookbook" is geared toward developers who are interested in working with the most up-to-date version of AndEngine, sporting the brand new GLES 2.0 branch. The book will be helpful for developers who are attempting to break into the mobile game market with plans to release fun and exciting games while eliminating a large portion of the learning curve that is otherwise inevitable when getting into AndEngine development.This book requires a working installation of eclipse and the required libraries, including AndEngine and its various extensions set up prior to working with the recipes.

What you will learn

  • Create your ultimate Android games with ease using recipes that take advantage of AndEngine s powerful framework and extensions
  • Make your games playable across a vast range of devices by implementing multi-touch, performance-optimizations, and accurate, screen-resolution scaling
  • Construct a customizable, front-end framework that simplifies menu and level creation
  • Use the Box2D extension to generate realistic, physics-based gameplay and simulations
  • Take advantage of source code for a full-featured game built with AndEngine
  • Make the most of vector-based graphics with AndEngine s SVG extension
  • Build animated, responsive Live-Wallpapers for Android s home screen using the AndEngine s Live-Wallpaper extension
  • Control every aspect of interaction that players have with your games by managing the Android application lifecycles

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 14, 2013
Length: 380 pages
Edition : 1st
Language : English
ISBN-13 : 9781849518987
Category :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $24.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jan 14, 2013
Length: 380 pages
Edition : 1st
Language : English
ISBN-13 : 9781849518987
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
AU$24.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
AU$249.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts
AU$349.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 128.98
Learning AndEngine
AU$60.99
AndEngine for Android Game Development Cookbook
AU$67.99
Total AU$ 128.98 Stars icon

Table of Contents

10 Chapters
AndEngine Game Structure Chevron down icon Chevron up icon
Working with Entities Chevron down icon Chevron up icon
Designing Your Menu Chevron down icon Chevron up icon
Working with Cameras Chevron down icon Chevron up icon
Scene and Layer Management Chevron down icon Chevron up icon
Applications of Physics Chevron down icon Chevron up icon
Working with Update Handlers Chevron down icon Chevron up icon
Maximizing Performance Chevron down icon Chevron up icon
AndEngine Extensions Overview Chevron down icon Chevron up icon
Getting More From AndEngine Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(25 Ratings)
5 star 44%
4 star 28%
3 star 16%
2 star 8%
1 star 4%
Filter icon Filter
Top Reviews

Filter reviews by




Natanael Fonseca Nov 17, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
The best book made for AndEngine, its examples worked fine to me specifically physics and shapes concepts, i recommend a lot if you are a beginner or advanced programmer.
Amazon Verified review Amazon
Efrain Astudillo Jan 31, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book "saved the bell" lol. I am doing a android game like a asignature project and there are a little information about it. This book is great
Amazon Verified review Amazon
Ramkys Tech May 26, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a great book if you are planning to develop an app using AndEngine. It covers lots of topics with examples.
Amazon Verified review Amazon
Maxim Yudin Apr 12, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
a cookbook, but it's not for beginners, it's not step-for-step tutorial book, only advices. Thanks so much to an author.
Amazon Verified review Amazon
J. Preston Jan 23, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
AndEngine is an amazing tool to get you up and going on Android programming. I began toying with AndEngine back in May 2013 as a means to support Android development. It's an approachable way of getting 2D games up and going quickly. There are some really good tutorials and samples out there, but Packt Publishing just released this nice book - AndEngine for Android Game Development Cookbook - that will support you if you're planning on exploring AndEngine. I've read other Packt texts, and they're VERY helpful in getting to the code/content you need without a lot of wasted filler. I've even used their Unity3D text for a few years in teaching a course on Unity3D.This cookbook approach is broken up into very specific topics (starting with the lifecycle of an AndEngine app through complex topics like physics interactions). Each topic begins with pre-requisite knowledge and an overview, then provides code/samples; explanation of what the code is doing comes next, and finally, the topic finishes with more details if you care to dive deeper. This is a nice approach that'll get you up and running quickly.I will point out that the code in the text is a subset of the overall text. So whereas something like a Deitel text provides a ton of code all in print, this cookbook text gives a necessary snippet and assumes you'll dive into the actual code (provided online) as needed. In my opinion, this is a good thing, but just be aware of this if you're not following how some stuff is working; just realize that there's more code provided that's not in the text.Unlike other texts that start from a "hello world" basic game and build into a single (or a few) larger game, this text (similar to other Packt cookbook texts), focuses on specific elements (like handling parallax scrolling, working with AndEngine entities, making a HUD, or handling collisions with Box2D). All of these topics are essential to making a 2D game, and you can drop in these concepts (and sample code) into your games rather quickly if you're using AndEngine. What's nice is that you're not just re-creating a single game throughout this text, but rather you're given lots of tricks and approaches to drop these essentials into your own game(s).I will caution you (as another reviewer stated) that this book presumes you know some basic game development concepts like design patterns (the singleton, object factory for examples) and resource pools (and why they're a good thing) among others. If you haven't picked these up earlier, then you'll need to take these ideas on faith or do a bit of background research to convince yourself these are valid approaches. But the upside is that if you're rusty on some of these concepts, this AndEngine cookbook text is an excellent, no-nonsense approach to getting going quickly. Also, be sure to check out the helpful PDF on how to set up your Android/AndEngine development environment/IDE in the code folder you download with the book; so look to this PDF file (downloaded with the code from the text) and follow it along if you need help getting your development environment set up.Since mobile is such an important and growing field, you should know something about Android development. If you want to see an engine that'll do all of the essentials and more, or if you've not done mobile/Android before, then check out AndEngine. And for the price of this book (especially the ecopy), the AndEngine Cookbook from Packt is a great choice to save you a lot of time as you dev your games.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.