Game Development Reference
In-Depth Information
sprite.setSize(0.9f, 0.9f *
sprite.getHeight() / sprite.getWidth());
sprite.setOrigin(sprite.getWidth()/2,
sprite.getHeight()/2);
sprite.setPosition(-sprite.getWidth()/2,
-sprite.getHeight()/2);
}
At first, the graphics module is queried to return the width and height of the display
(for example, a desktop window or the screen of an Android device) and calculate
an appropriate width and height for the field of view of the camera. Then, a new
instance of
SpriteBatch
is created so that images can be drawn and made visible
with the camera. The next step is to load a texture using the files module to get a file
handle to
data/libgdx.png
.
Gradle users will find only two lines of code in the
create()
method
and only four lines of code in the
render()
method. The
assets
folder in the
demo-android
project will contain only an image labeled
badlogic.jpg
. Read and understand this code; the complete code is
given at the end of this section.
The loaded texture looks like the following screenshot: