Book Image

Learning Android Game Development

By : Nikhil Malankar
Book Image

Learning Android Game Development

By: Nikhil Malankar

Overview of this book

In this book, we’ll start with installing Android studio and its components, and setting it up ready for Android N. We teach you how to take inputs from users, create images and interact with them, and work with sprites to create animations. You’ll then explore the various collision detection methods and use sprites to create an explosion. Moving on, you’ll go through the process of UI creation and see how to create buttons as well as display the score and other parameters on screen. By the end of the book, you will have a working example and an understanding of a 2D platform game like Super Mario and know how to convert your 2D games to 3D games.
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
4
Creating Sprites and Interactive Objects

Creating the UI for our game


If you are not familiar with the term the UI, you must be wondering what the heck is it? UI is an abbreviation for User Interface. To put simply, a UI can consist of all the information you need to display on your game screen or your onscreen controls. Common elements of a UI include the following:

  • Text displayed on the screen
  • Buttons
  • Joystick pad
  • Tutorial instructions

In this part of our chapter, we will learn how to display text on the screen. We will also instruct the player how to play the game. We will display the following on our screen:

  • Distance ran
  • Best score
  • Instructions on how to play

So, here we have to display the best score. However, we haven't created our best score variable yet. For this part, we will work entirely in our GameView.java file. So, let's define our best score variable in this class:

private int bestScore;

We're now ready to show our UI data on the screen. Our UI will be entirely based on the draw() function, and so we will define a method called...