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

Rendering our object on screen


In our previous chapter, we created a class for our Triangle object; however, if you run your game, it will still show a blank screen since we have not used our render class to display it. We need to create an object for our newly defined class, and then using our GL reference, we will draw/render it on our screen. Open up your MyGLRenderer.java file and let's start by declaring a variable of our triangle. We won't be altering any of our code that we wrote in onSurfaceCreated() or onSurfaceChanged() methods.

In order to draw our object on screen, we will simply follow these steps:

  1. Define a variable of our Triangle class.
  2. Assign a reference to it in our constructor.
  3. Using gl, access the draw() method in our Triangle to display it on screen.

Let's take a look at how we can do that; just type in the code marked in bold in your MyGLRenderer.java file:

//The import statements are same as our previous chapter

public class MyGLRenderer implements GLSurfaceView.Renderer...