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

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