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

Rotating our object


By now, you must have understood that any changes in the rendering of an object have to be done in the MyGLRenderer, whereas any properties that are local to our object are to be done in the respective object's file. So, we will write our rotation code in our MyGLRenderer.java file because rotating an object is a part of the rendering process.

Here's our logic to rotate our triangle:

  • We take our rotation angle
  • We rotate our object in a specified rotation angle
  • We increment our rotation angle

Let's do it; we will simply declare two variables at the start for our rotational angle and speed; then in our onDrawFrame() method, implement our rotation logic, as follows:

//Import statements as before
public class MyGLRenderer implements GLSurfaceView.Renderer {

    Triangle triangle;

    private float angleTriangle = 0.0f;
    private float speedTriangle = 0.5f;

    public MyGLRenderer(Context context) {
        triangle = new Triangle();
    }

// No changes in our onSurfaceCreated...