The Beginner's Guide to Android Game Development by James Cho

The Beginner's Guide to Android Game Development by James Cho

Author:James Cho
Language: eng
Format: azw3
Publisher: Glasnevin Publishing
Published: 2014-10-27T05:00:00+00:00


Ellio: Optimization Matters

Ellio is a simple two-button game, but the nature of this infinite runner necessitates a discussion of optimization.

The Issue of Memory Management

Until now, we’ve largely ignored memory usage; we’ve created objects at will, assuming that our machine will always have plenty of memory (RAM) to store these as variables for as long as we need. When we start developing for Android, this assumption may not always hold. Mobile devices tend to have smaller amounts of memory than do computers, and this memory tends to be shared across multiple applications simultaneously. This makes memory management an important issue that you should actively think about when developing games, and we will start this process with Ellio.

If you look again at Figure 6-1, you will notice that Ellio has to avoid a series of yellow blocks coming from the right. Let me ask you this question. What should we do with the yellow blocks that have gone past the left side of the screen? These blocks are no longer visible, so keeping them around means that they will take up memory for no reason. Continuing to waste processing power to update them and render them will mean that our game will slow down with time.

You may have answered the question by saying, “We should destroy the unused blocks.” While that may sound like a great idea, that would mean we must create a new set of blocks to replace the destroyed ones. This is bad for a couple of reasons. To understand why, let’s talk about some optimization techniques that will make our game run faster.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.