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 colors to our object


In this part, we will demonstrate how we can use different colors to texture our object. We will use RGB values using a colorBuffer to fetch values from the colors of the vertices. After this, we will enable the color-array client state, and then these colors are rendered together with the vertices in glDrawElements().

Here, we will again use nio's FloatBuffer to declare our colorBuffer variable. Here are the steps we would use to add color to our object:

  1. We declare our colorBuffer variable.
  2. We declare our color array variable.
  3. We copy our color vertices data to our buffer.
  4. Enable our color array.
  5. Define color array buffer.
  6. Disable color array.

Also, since this is a native property of the triangle, we will write this code in our Triangle.java class that we created and not in the MyGLRenderer.java class. Type in the code marked in bold keeping in mind the preceding steps:

//Import statements remain the same
public class Triangle {
private FloatBuffer vb;
    private FloatBuffer...