Book Image

Android Game Programming by Example

By : John Horton
Book Image

Android Game Programming by Example

By: John Horton

Overview of this book

Table of Contents (18 chapters)
Android Game Programming by Example
About the Author
About the Reviewers
Platformer – Guns, Life, Money, and the Enemy

Setting up your development environment

All the code in this book and the download bundle will work in your favorite Android IDE. However, I found the latest version of Android Studio exceptionally friendly to use and the code was written and tested in it as well.

If you don't currently use Android Studio, I encourage you to give it a try. Here is a quick overview of how to get up and running quickly. This guide includes steps to install the Java JDK in case you are completely new to Android development.


If you already have your preferred development environment ready to go then jump straight to Chapter 2, Tappy Defender – First Step.

The first thing we need to do is prepare your PC to develop for Android using Java. Fortunately, this is made quite simple for us.


If you are learning on Mac or Linux everything in this book will still work. The next two tutorials have Windows-specific instructions and screenshots. However, it shouldn't be too difficult to vary the steps slightly to suit Mac or Linux.

All we need to do is:

  1. Install the Java Development Kit (JDK), which allows us to develop in Java.

  2. Then install Android Studio to make Android development fast and easy. Android Studio uses the JDK and some other Android-specific tools that get automatically installed when we install Android Studio.

Installing the JDK

The first thing we need to do is get the latest version of the JDK. To complete this guide, perform the following instructions:

  1. We need to be on the Java website, so visit:

  2. Find the three buttons shown here and click on the one that says JDK that is highlighted in the following image. They are on the right-hand side of the web page. Then, click on the Download button under the JDK option:

  3. You will be taken to a page that has multiple options to download the JDK. In the Product/File Description column, you need to click the option that matches your operating system. Windows, Mac, Linux, and some other less common options are all listed.

  4. A common question asked here is, do I have 32- or 64-bit windows? To find out, right-click on your My Computer icon (This PC on Windows 8), click on the Properties option, and look under the System heading at the System type entry:

  5. Click on the somewhat hidden Accept License Agreement checkbox:

  6. Now, click on download for your OS and type as previously determined. Wait for the download to finish.

  7. In your downloads folder, double-click on the file you just downloaded. The latest version at the time of writing for a 64-bit Windows PC was jdk-8u5-windows-x64. If you are using Mac/Linux or have a 32-bit OS, your filename will vary accordingly.

  8. In the first of several install dialogs, click on the Next button and you will see the following dialog box:

  9. Accept the defaults shown in the previous image by clicking on Next. In the next dialog box, you can accept the default install location by clicking on Next.

  10. Next up is the last dialog of the Java installer; for this click on Close.


    The JDK is now installed. Next, we will make sure that Android Studio is able to use the JDK.

  11. Right-click on your My Computer icon (This PC on windows 8) and click on Properties | Advanced system settings | Environment Variables... | New... (under System variables, not under User variables). Now, you can see the New System Variable dialog box:

  12. Type JAVA_HOME for Variable name: and enter C:\Program Files\Java\jdk1.8.0_05 for the Variable value: field. If you installed the JDK somewhere else, then the file path you enter in the Variable value: field will need to point to wherever you put it. Your exact file path will likely have a different ending to match the latest version of Java at the time you downloaded it.

  13. Click on OK to save your new settings.

  14. Now under System variables, click on Path and then click on the Edit... button. At the very end of the text in the Variable value: field, enter the following text to add our new variable to the file paths that Windows will use, ;JAVA_HOME. Be sure not to miss the semicolon from the beginning.

  15. Click on OK to save the updated Path variable.

  16. Now, click on OK again to clear the Advanced system settings dialog box.

The JDK is now installed on our PC.

Installing Android Studio

Without delay, let's get Android Studio installed, and then we can begin our first game project. Visit:

  1. Click on the button labeled DOWNLOAD ANDROID STUDIO FOR WINDOWS to start the Android Studio download. This will take you to another web page with a very similar looking button to the one you just clicked on.

  2. Accept the license by checking the checkbox and commence the download by clicking the button labeled DOWNLOAD ANDROID STUDIO FOR WINDOWS and wait for the download to complete.

  3. In the folder you just downloaded Android Studio to, right-click on the android-studio-bundle-135.12465-windows.exe file and click on Run as administrator. The end of your filename will vary depending on the version of Android Studio and your operating system.

  4. When asked if you want to allow the following program from an unknown publisher to make changes to your computer, click on Yes. On the next screen, click on Next.

  5. On the screen pictured here, you can choose which users of your PC can use Android Studio. Choose which is right for you as all options will work, and then click on Next:

  6. In the next dialog, leave the default settings and then click on Next.

  7. On the Choose start menu folder dialog box leave the defaults and click on Install.

  8. On the Installation complete dialog, click on Finish to run Android Studio for the first time.

  9. The next dialog is for users who have already used Android Studio, so assuming you are first-time user, select the I do not have a previous version of Android Studio or I do not want to import my settings checkbox. Then click on OK:

That was the last piece of software we needed. We will begin to use Android Studio straight away in the next chapter.