Texture rendering with SpriteBatch
A texture is a bitmap image that gets applied to a surface through mapping. Rendering textures on the screen will be our first step in getting to know the Libgdx 2D graphics API. Once you learn a few simple operations with textures, you will be able to build relatively complex scenes for your games.
To illustrate the procedure, we are going to make use of a friendly caveman, who we will show at different positions, sizes, and orientations.
Getting ready
You need the samples
projects to follow this recipe, so make sure you already have them in your Eclipse workspace. You will find the caveman texture in data/caveman.png
, inside the data
folder in the Android project.
How to do it…
The code for this recipe is hosted in the SpriteBatchSample
class, which has the classic methods of an ApplicationListener
interface implementation. Note that only the most relevant pieces of code are shown in this recipe as snippets; you can, however, study the full source...