Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Android Game Development

You're reading from   Learning Android Game Development A Beginner's guide to developing popular Android games

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781785880957
Length 238 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Nikhil Malankar Nikhil Malankar
Author Profile Icon Nikhil Malankar
Nikhil Malankar
Arrow right icon
View More author details
Toc

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...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime