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 ...
Get Libgdx Cross-platform Game Development Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.