Book Image

Learning Java by Building Android Games - Third Edition

By : John Horton
5 (1)
Book Image

Learning Java by Building Android Games - Third Edition

5 (1)
By: John Horton

Overview of this book

Android is one of the most popular mobile operating systems today. It uses the most popular programming language, Java, as one of the primary languages for building apps of all types. Unlike most other Android books, this book doesn’t assume that you have any prior knowledge of Java programming, instead helps you get started with building Android games as a beginner. This new, improved, and updated third edition of Learning Java by Building Android Games helps you to build Android games from scratch. Once you've got to grips with the fundamentals, the difficulty level increases steadily as you explore key Java topics, such as variables, loops, methods, object-oriented programming (OOP), and design patterns while working with up-to-date code and supporting examples. At each stage, you'll be able to test your understanding by implementing the concepts that you’ve learned to develop a game. Toward the end, you’ll build games such as Sub Hunter, Retro Pong, Bullet Hell, Classic Snake, and Scrolling Shooter. By the end of this Java book, you'll not only have a solid understanding of Java and Android basics but will also have developed five cool games for the Android platform.
Table of Contents (24 chapters)

Using the Canvas class

Let's look at the code and the different stages required to get drawing, and then we can quickly move on to drawing something for real, with the help of the Canvas demo app.

Preparing the objects of classes

Remember, back in Chapter 2, Java – First Contact, that I said the following:

In Java, a blueprint is called a class. When a class is transformed into a real working thing, we call it an object or an instance of the class.

The first step is to turn the classes (blueprints) we need into real working things – objects/instances. This step is analogous to declaring variables.

Important note

We have already done this with the Random class in the previous chapter and will explore this in more depth in Chapter 8, Object-Oriented Programming.

First, we state the type, which in this case happens to be a class, and then we state the name we would like our working object to have:

// Here are all the objects(instances)
// of...