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 an explosion to our game


In Chapter 7, Adding Boundaries and Using Sprites to Create Explosions, we have already created our ExplosionEffect.java class file. Now, we are left with just one task: to spawn our explosion on the screen. Now, just for reference, we will take a look at the image we will use for our explosion file:

Explosion.png file sprite sheet

Note that the last frame of our explosion has almost no image in it. This is because we are not going to destroy this object; we are simply going to spawn it and let it play its animation for now.

Let's proceed and get our explosion running on our game screen. Again, here we will break down our process into simple steps.

Creating variables

As you should be aware by now, we will work on our GameView.java file to display our explosion. So, open up your GameView.java file. We will start by creating a few variables, as follows:

private ExplosionEffect explosionEffect;
private long startReset;
private boolean reset;
private boolean started...