Slick Icon and User Keyboard Input
This section I'll show you how to create your own icon for your
application and react to user keyboard input. For icon, the image can't be
too big, so go ahead and create any "16 x 16 pixel" images. Lets look
at the example
The example will load two images, one image
will use as the background and the other one will be able to control by the
user.
Image backGround = null;
We will use this as our background image.
Image saber = null;
This is a saber image, the user have control to rotate, move left and right or
up and down.
Lets break down the code,
float x = 50;
float y = 50;
It holds the start location of the saber image, we update the
x and y values
each time the image changes its location on the x and y axis.
This time we will be using the update
method whenever the image changes its
location. We have to update the image to its new location
in addition to that we have to "re-render"
the image again. Whenever we want to get keyboard input from user we have to use
the follow method.
Input getUserInput = container.getInput();
container
is just an object we created in our parameter using "
GameContainer
".
The rest are just a series of "
if-statement condition " to react to a
key-press or a key push.
Now, for creating your own icon, all we need
is to call the " setIcon()
", method inside our main method.
(Note: 0.5f, f stands for floating point,
this implies the value 0.5f is a floating point number)