Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
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
Learning Java by Building Android Games
Learning Java by Building Android Games

Learning Java by Building Android Games: Extend your game development skills while learning Java – follow this book and learn Java for Android to enter the world of Android games development with greater confidence

eBook
Mex$723.59 Mex$803.99
Paperback
Mex$803.99 Mex$1004.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning Java by Building Android Games

Chapter 2. Getting Started with Android

In this chapter, we will take a roller coaster ride through all the Android topics that you need to learn in order to get started with Java. It won't just be theoretical though. We will be designing a user interface (UI) of a game menu and we will see and edit our first Java code as well.

In addition, we will see how we can run our apps in either an Android emulator on our PC/Mac or on a real Android device if we have one.

Some of what we will cover in this chapter will be the tip of the iceberg. That is, there is a lot more below the surface to some of the topics we discuss than would be appropriate for the second chapter of a learning Java book. Sometimes, we might need to take a bit of information on faith.

This will then enable us to actually design and run our very own Android app by the end of this chapter. Then we can start learning Java for real at the beginning of the next chapter.

If this chapter seems a little tough, then don...

Our first game project

Now we will get straight down to actually doing something with Android Studio. Run Android Studio by double-clicking on the Android Studio icon either on your desktop's start menu or in the folder where you installed it.

Note

If you get any errors in a dialog box mentioning Privilege elevation, then try running Android Studio with administrator privileges. To do this, find the Android Studio icon by clicking on the Windows Start button and searching for Android Studio. Now right-click on the icon and click on Run as administrator. Do this every time you run Android Studio.

Preparing Android Studio

So with Android Studio and Java installed, we just need to add the latest versions of the Android API that we will use to make our first game. Here is what to do to install the API:

  1. From the menu bar at the top of the Android Studio UI, navigate to Tools | Android | SDK Manager. Scroll down in the Android SDK Manager window and select the checkbox for Android 4.4.2 (API...

Exploring Android Studio

Android Studio is a very deep tool, but it is only necessary to learn one part at a time in order to get started. What might be useful for us is naming a few parts of the UI so that we can refer to them easily as we progress through the book.

Take a look at this numbered diagram and a quick explanation of some of the key parts of Android Studio. If you can, try and memorize the parts to make future discussions of them easier for you.

Exploring Android Studio

Here is a handy table that you can quickly refer to and remember which part of Android Studio we are referring to. What follows is a more detailed explanation of each area.

Number

Name

1

Project Explorer

2

The editor

3

Menu bar

4

Toolbar

5

Navigation bar

6

Important tool windows

  • Project Explorer (1): This is shown as 1 in the screenshot and is a bit like Windows Explorer. It shows us all the files and folders that have been generated for our project. We will do a number of things from here as the book continues. Actually...

Using the Android Studio visual designer

The Android Studio editor window is a very dynamic area. It presents different file types in the most useful way possible. A little earlier, when we created our project, it also made a basic UI for us. UIs in Android can be built-in Java code or, as we will see, in a visual designer without the need for a single line of Java. However, as we will investigate after we have built the UI of our game menu, to get the UI to do anything useful, we need to interact with it. This interaction is always done with Java code. The visual designer also generates the UI code for us. We will take a very quick look at that too.

As the book progresses, we will mainly shy away from Android UI development, as that is a staple of more non-game apps. We will instead spend more time looking at directly drawing pixels and images to make our games. Nonetheless, the regular Android UI has its uses, and the Android Studio visual designer is the quickest way to get started.

Let...

Structuring our code for Android

If you have ever used an Android device, you have probably noticed that it works quite differently from many other operating systems. For example, you are using an application—say you're checking what people are doing on Facebook. Then you get an e-mail notification and you tap the e-mail icon to read it. Midway through reading the e-mail, you might get a Twitter notification and because you're waiting on important news from someone you follow, you interrupt your e-mail reading and change the app to Twitter with a touch.

After reading the tweet, you fancy a game of Angry Birds, but midway through the first daring fling, you suddenly remember that Facebook post. So you quit Angry Birds and tap the Facebook icon.

Then you resume Facebook, probably at the same point you left it. You could have resumed reading the e-mail, decided to reply to the tweet, or started an entirely new app. All this backwards and forwards takes quite a lot of management...

Our first look at Java

So what about all that code that Android Studio generated when we created our new project earlier? This is the code that will bring our game menu to life. Let's take a closer look. The very first line of code in the editor window is this:

package com.packtpub.mathgamechapter2;

This line of code defines the package that we named when we first created the project. As the book progresses, we will write more complex code that spans more than one file. All the code files we create will need the package they belong to, clearly defined like the previous line of code, at the top. The code doesn't actually do anything in our game. Notice also that the line ends with a semicolon (;). This is a part of the Java syntax and it denotes the end of a line of code. Remove a semicolon and you will get an error because Android Studio tries to make sense of two lines together. Try it if you like.

Tip

Remember that if you are going to be copying and pasting the code from the download...

Our first game project


Now we will get straight down to actually doing something with Android Studio. Run Android Studio by double-clicking on the Android Studio icon either on your desktop's start menu or in the folder where you installed it.

Note

If you get any errors in a dialog box mentioning Privilege elevation, then try running Android Studio with administrator privileges. To do this, find the Android Studio icon by clicking on the Windows Start button and searching for Android Studio. Now right-click on the icon and click on Run as administrator. Do this every time you run Android Studio.

Preparing Android Studio

So with Android Studio and Java installed, we just need to add the latest versions of the Android API that we will use to make our first game. Here is what to do to install the API:

  1. From the menu bar at the top of the Android Studio UI, navigate to Tools | Android | SDK Manager. Scroll down in the Android SDK Manager window and select the checkbox for Android 4.4.2 (API 19).

    Note...

Exploring Android Studio


Android Studio is a very deep tool, but it is only necessary to learn one part at a time in order to get started. What might be useful for us is naming a few parts of the UI so that we can refer to them easily as we progress through the book.

Take a look at this numbered diagram and a quick explanation of some of the key parts of Android Studio. If you can, try and memorize the parts to make future discussions of them easier for you.

Here is a handy table that you can quickly refer to and remember which part of Android Studio we are referring to. What follows is a more detailed explanation of each area.

Number

Name

1

Project Explorer

2

The editor

3

Menu bar

4

Toolbar

5

Navigation bar

6

Important tool windows

  • Project Explorer (1): This is shown as 1 in the screenshot and is a bit like Windows Explorer. It shows us all the files and folders that have been generated for our project. We will do a number of things from here as the book continues. Actually,...

Using the Android Studio visual designer


The Android Studio editor window is a very dynamic area. It presents different file types in the most useful way possible. A little earlier, when we created our project, it also made a basic UI for us. UIs in Android can be built-in Java code or, as we will see, in a visual designer without the need for a single line of Java. However, as we will investigate after we have built the UI of our game menu, to get the UI to do anything useful, we need to interact with it. This interaction is always done with Java code. The visual designer also generates the UI code for us. We will take a very quick look at that too.

As the book progresses, we will mainly shy away from Android UI development, as that is a staple of more non-game apps. We will instead spend more time looking at directly drawing pixels and images to make our games. Nonetheless, the regular Android UI has its uses, and the Android Studio visual designer is the quickest way to get started.

Let...

Left arrow icon Right arrow icon

Description

If you are completely new to either Java, Android, or game programming and are aiming to publish Android games, then this book is for you. This book also acts as a refresher for those who already have experience in Java on another platforms or other object-oriented languages.

What you will learn

  • Set up an efficient, professional game development environment in Android Studio
  • Build your very own Android UI using easy touse tools in Android Studio
  • Add realtime interaction with Java threads and implement locking/handling screen rotation, pixel graphics, clicks, animation, sound FX, and many other features in your games
  • Explore objectoriented programming (OOP) and design scalable, reliable, and wellwritten Java games or apps on almost any Android device
  • Build and deploy a graphical pongstyle game using advanced OOP concepts
  • Explore APIs and implement advanced features such as online leaderboards and achievements using Google game services
  • Make your game compelling to be the next big hit on Google Play market with a content update strategy and ingame marketing

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 29, 2015
Length: 392 pages
Edition : 1st
Language : English
ISBN-13 : 9781784393847
Vendor :
Google
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jan 29, 2015
Length: 392 pages
Edition : 1st
Language : English
ISBN-13 : 9781784393847
Vendor :
Google
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 Mex$85 each
Feature tick icon Exclusive print discounts
$279.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 Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 2,511.17 3,138.97 627.80 saved
Android Game Programming By Example
Mex$803.99 Mex$1004.99
Learning Java by Building Android Games
Mex$803.99 Mex$1004.99
Android NDK Beginner`s Guide - Second Edition
Mex$903.19 Mex$1128.99
Total Mex$ 2,511.17 3,138.97 627.80 saved Stars icon

Table of Contents

11 Chapters
1. Why Java, Android, and Games? Chevron down icon Chevron up icon
2. Getting Started with Android Chevron down icon Chevron up icon
3. Speaking Java – Your First Game Chevron down icon Chevron up icon
4. Discovering Loops and Methods Chevron down icon Chevron up icon
5. Gaming and Java Essentials Chevron down icon Chevron up icon
6. OOP – Using Other People's Hard Work Chevron down icon Chevron up icon
7. Retro Squash Game Chevron down icon Chevron up icon
8. The Snake Game Chevron down icon Chevron up icon
9. Making Your Game the Next Big Thing Chevron down icon Chevron up icon
A. Self-test Questions and Answers Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(30 Ratings)
5 star 60%
4 star 0%
3 star 23.3%
2 star 3.3%
1 star 13.3%
Filter icon Filter
Top Reviews

Filter reviews by




angelicarahpsody Jul 07, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I will return to this review after finishing this book, however:I purchased this book after months of exhaustive web searching and learning on my own through trial and error. I had a light understanding of basic programming concepts. I was not satisfied with the material that I could get my hands on in terms of learning Java or working with Android Studio. I came across this book and read the reviews which were highly positive. The author states that he takes a slightly different approach then the normal way of teaching. I find this to be the case, but also, the author's writing style is not similar to the vast number of programming language websites and book excerpts I have read. It is much simpler and more engaging. It is concise and uncomplicated. The author, while assuming the reader is a beginner (which I am) does not beat you over the head with paragraphs of writing that doesn't really apply, endless "real-world" analogies, or heavy use of technical jargon. The author illustrates core concepts expertly.A lot of Java writing that I have read basically throws a lot of code at you and says "We'll worry about this later". This leaves you with a feeling that you are learning too much too quickly and will not know how to piece it together once explained. The author does feed you code in a similar manner, but with smaller chunks, built plainly around a key concept, and then explains what happens without going into heavy endless detail.I downloaded the Kindle version after a purchase of the book, due to it being heavily discounted. I figured I would take a look at it before receiving the paperback. All of a sudden, several hours later and eighty pages in, I feel confident in what I've learned and feel like I can explain it plainly.
Amazon Verified review Amazon
serj May 06, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
thanksnice book
Amazon Verified review Amazon
GoWestYoungMan Feb 23, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
An excellent starter manual for both Android and Java. Only potential drawback is the Android Studio was an older version so modification are needed to some of the code examples. Highly recommended!
Amazon Verified review Amazon
Yhal Htet Aung Oct 24, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
One of the Best Books to learn about Android Game Programming and at the same time, the explaination is simple and easy to understand. I recommend this book for the new developer to study about Android and Java. This is one of the best books ever.
Amazon Verified review Amazon
Jean Dec 02, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Tres bon produit correspond a la description livraison tres rapide vraiment aucun regret une valeur sur je recommande a 100%
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.

Modal Close icon
Modal Close icon