Book Image

Mastering Android Game Development

By : Raul Portales
Book Image

Mastering Android Game Development

By: Raul Portales

Overview of this book

Table of Contents (18 chapters)
Mastering Android Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
API Levels for Android Versions
Index

Preface

Android is the most widespread Operating System and games are what people spend most time using on their phones. Video games have never been easier to make and distribute. Who would not want to make games for Android?

And on top of this, making games is fun!

You will build a real-time game from scratch using the Android SDK. Starting with the creation of a game engine and moving into handling user input, doing efficient drawing, implementing collision detection, playing sound effects, using animations, and so on. You will learn all the aspects of developing a game using a space shooter game as the example that will evolve with you throughout the chapters.

What this book covers

Chapter 1, Setting Up the Project, allows you to set up the project and will describe in which cases it makes sense to use the Android SDK for a game and in which cases it is best to use an external engine. We will create the top-level architecture of a game engine and study how it is different from the one of a typical app, explaining why there is an update thread and why it is separated from the input thread and also from the draw thread.

Chapter 2, Managing User Input, discusses how to read and process user input and how to make controls for our game, from making a virtual gamepad to evolving it as a virtual joystick to adding support for physical controllers. Finally, we'll introduce how to use sensors as input.

Chapter 3, Into the Draw Thread, explores how drawing on a canvas provides better performance. We will discuss the pros and cons of using a normal view versus a SurfaceView.

Chapter 4, Collision Detection, explains how to run and add a basic collision detection system to our game and shows how it fits inside the game engine.

Chapter 5, Particle Systems, helps us learn several uses of particle systems and we'll build one based on the Leonids library wherein a particle system is a big part of a game.

Chapter 6, Sound FX and Music, explores the different options to play sound effects and music in Android and we'll build a SoundManager to handle them since a game feels incomplete without sounds.

Chapter 7, Menus and Dialogs, explains techniques to use the same layouts across phones and tablets and learn how to make them work on both because a compelling UI requires nice menus and dialogs. Finally, since the dialogs available in the Android framework are quite limited, we'll see how we can create more complex dialogs.

Chapter 8, The Animation Framework, dives into the different ways Android offers to animate views and objects and what they can be used for, from frame-by-frame animations to view animations and property animators.

Chapter 9, Integrating Google Play Services, covers the tools that Google Play Services offers for game developers. We'll see the integration of achievements and leaderboards in detail, take an overview of events and quests, save games, and use turn-based and real-time multiplaying.

Chapter 10, To the Big Screen, explores the extra restrictions that games have when going to Android TV, mainly screen overcast and controller-based navigation and also extra options in the Manifest that are specific for Android TV.

Appendix, API Levels for Android Versions, lists all 22 API levels, from Base to Lollipop_MR1, along with the version code.

What you need for this book

For this book, you will need the latest version of Android Studio and the Android SDK for Lollipop or newer (API level 22) versions, which you can download using Android Studio.

Android Studio is a free tool that you can download from https://developer.android.com/sdk/index.html and it runs on Windows, Mac, and Linux.

It is advisable to have several Android devices for testing, but is not necessary. It is also advisable to have a Bluetooth game controller (which will become useful for any mobile game developer anyway), but it is not required.

Who this book is for

If you are an Android developer who wants to make games and doesn't want to learn a new third-party tool or engine, this book is for you. Make the journey of building a game from scratch to get insights into all the aspects of game development, from implementing your own engine to getting a game ready for Android TV, always with a hands-on approach.

Conventions

In this book, you will find a number of text styles 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: "It will be used intensively during onUpdate and onDraw."

A block of code is set as follows:

public void removeGameObject(final GameObject gameObject) {
  mObjectsToRemove.add(gameObject);
  mActivity.runOnUiThread(gameObject.mOnRemovedRunnable);
}

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

<style name="iconButton" >
  <item name="android:background">@drawable/icon_button_bg</item>
  <item name="android:layout_width">@dimen/btn_round_size</item>
  <item name="android:layout_height">@dimen/btn_round_size</item>
  <item name="android:padding">@dimen/round_button_padding</item>
  <item name="android:focusable">true</item>
</style>

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "We have a link at the bottom named Get resources that pops up a dialog with the string resources we need."

Note

Warnings or important notes appear in a box like this.

Tip

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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail and mention the book's title in 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 at www.packtpub.com/authors.

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 from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with 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 https://www.packtpub.com/sites/default/files/downloads/1774OS_ImageBundle.pdf.

Errata

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 could 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 http://www.packtpub.com/submit-errata, 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 to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.