Book Image

Learning LibGDX Game Development- Second Edition

Book Image

Learning LibGDX Game Development- Second Edition

Overview of this book

Table of Contents (21 chapters)
Learning LibGDX Game Development Second Edition
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating game objects


Before we start implementing each individual game object, we will create an abstract class called AbstractGameObject. It will hold all the common attributes and functionalities that each of our game objects will inherit from.

Note

You might want to check the Canyon Bunny class diagram in Chapter 3, Configuring the Game, again to get an overview of the class hierarchy of the game objects.

Create a new file for the AbstractGameObject class and add the following code:

package com.packtpub.libgdx.canyonbunny.game.objects;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;

public abstract class AbstractGameObject {

    public Vector2 position;
    public Vector2 dimension;
    public Vector2 origin;
    public Vector2 scale;
    public float rotation;

public AbstractGameObject () {
    position = new Vector2();
    dimension = new Vector2(1, 1);
    origin = new Vector2();
    scale = new Vector2(1, 1);
    rotation = 0;
}

  public void...