O'Reilly logo

Libgdx Cross-platform Game Development Cookbook by Alberto Cejas Sánchez, David Saltares Márquez

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required