Game Development Reference
In-Depth Information
For more information about projections, check out the great article orthographic
versus perspective by Jeff Lamarche at
http://iphonedevelopment.blogspot.
The
batch
variable is of the class type
SpriteBatch
. This is where you send all your
drawing commands to LibGDX. Beyond the ability of this class to draw images, it is
also capable of optimizing the drawing performance under certain circumstances.
The
texture
variable is of the class type
Texture
. It holds a reference to the actual
image; the texture data that is stored in memory at runtime.
The
sprite
variable is of the class type
Sprite
. It is a complex data type that contains
lots of attributes to represent a graphical object that has a position in 2D space, width,
and height. It can also be rotated and scaled. Internally, it holds a reference to a
TextureRegion
class that in turn is a means to cut out a certain portion of a texture.
Now that we have a basic knowledge of the involved data types, we can advance
to the implementation details of the
ApplicationListener
interface.
In the
MyDemo
class, the only methods containing code are
create()
,
render()
,
and
dispose()
. The remaining three methods are left empty, which is just fine.
The create() method
The
create()
method contains the initialization code to prepare the application on
startup, as shown in the following code snippet:
@Override
public void create() {
float w = Gdx.graphics.getWidth();
float h = Gdx.graphics.getHeight();
camera = new OrthographicCamera(1, h/w);
batch = new SpriteBatch();
texture = new Texture(Gdx.files.internal("data/libgdx.png"));
texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegion region =
newTextureRegion(texture, 0, 0, 512, 275);
sprite = new Sprite(region);