Book Image

Libgdx Cross-platform Game Development Cookbook

Book Image

Libgdx Cross-platform Game Development Cookbook

Overview of this book

Table of Contents (20 chapters)
Libgdx Cross-platform Game Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Taking advantage of Libgdx sprites


The Texture and TextureRegion objects have proven sufficient to render 2D game worlds, but Libgdx also offers the Sprite class to make our lives more enjoyable. The Sprite class is nothing less than a glorified TextureRegion, adding state properties such as color, position, scale, and rotation.

For this recipe's example, we have taken the jungle scene in TextureAtlasSample and added some modifications so we can play around with sprites. To begin with, Mr. Caveman will constantly follow the mouse. Whenever the user touches the screen or performs a left-click, the dinosaur will acquire a new color tint. Finally, the caveman will rotate upon scrolling and vary its size when scrolling while holding the right mouse button.

Getting ready

As always, import the sample projects into your Eclipse workspace.

How to do it…

As you will see in just a moment, sprites are extremely easy to use. Please focus your attention on SpriteSample.java. Besides the typical camera, viewport...