Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
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
 Malankar Malankar
Author Profile Icon Malankar
Malankar
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Introduction to Android N and Installation of Android SDK FREE CHAPTER 2. Getting Familiar with Android Studio 3. Managing Inputs 4. Creating Sprites and Interactive Objects 5. Adding Animation to Your Game 6. Collision Detection and Basic Artificial Intelligence 7. Adding Boundaries and Using Sprites to Create Explosions 8. Adding an Explosion and Creating a UI 9. Converting Your Game from 2D to 3D 10. Working Further on 3D Game

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...
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 $15.99/month. Cancel anytime
Visually different images