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

Adding boundaries


As we are quite familiar with the process of creating a new class, we will simply create our two new classes for our upper and lower boundary and call them UpperBoundary.java and LowerBoundary.java, respectively. We have the following objectives for our boundaries:

  • Make them appear at the top and bottom of our game screen
  • If a player collides with them, then reset the game

With these objectives in mind, we will move ahead to create boundaries for our game.

Creating the classes for our boundaries

Before actually creating our boundaries, we will need an image sprite in order to make them visible on the screen. For this purpose, we will take a simple sprite with a plain color. Here's the sprite that we will be using for our game:

Our ground.png file

Also, we will place this file in our res/drawable folder as we did for our previous image files. Once you are done with this, move on to the next part.

So now, let's create our UpperBoundary.java class. Go ahead, create a new class and...