Sprite is a 2 dimensional object in a flat format used to develop a game based on two-dimensional graphics. Surely you still remember with a game called "Contra" there there are two playable characters, Bill Rizer and Lance Bean. If we play it seemed the games actor moves to the left and to the right in accordance with the input joystick that we use, and Sprite Bill Rizer and Lance Bean on the game moves according to the input of the joystick that we use and we can also see the animation of the sprite.
Sprite Bill Rizer and Lance Bean are animated sprites, or an animated objects in a condition that is determined by the programmer of the game, for example when the character Bill Rizer is moving to the right then it will display the animation runs.
|
A single strip of Sprite character Bill Rizer in the NES game 3 with the index 6 columns and 2 rows (image source: www.spriters-resource.com) |
Based on the theory that already described above, then it appears a question, "How do we display a sprite and animating sprites in the game application that will be created?", on a simple game application that has been built using the Java programming language and supported by the library from Golden T Game Engine. If we look at sprites like in the image above, the Sprite has index 6.2 means a strip of Sprite above has 6 columns and 2 rows. For example we want the sprite doing animation on the game area, then before we start coding take a variable declaration for Sprite.
In order to do the animation for the sprite, we use a AnimatedSprite class that derives from the class library Golden T Game Engine and declared with the name of the variable "Bill_Rizer". As seen on line at number 3, the sprite variable will be inserted into the sprite group that serves to set the Sprite in the game area such as rendering, collision between sprite objects on the game area, and increase or decrease the amount of sprite object that exists on the game area.
The variables of the class AnimatedSprite which contains the parameters of the sprite image directory will be used by the class playfield to render objects from the Sprite. On the application of games that have been made, there is a class named by playfield that was declared by the variable "playField" as seen in the code line number 2. After determining the variable Animated sprites, Playfield, and the sprite group, the next step is to initialize the variables property of the game on a method named "initresources ()" variable from the property game is a variable component of sprites, background picture, the position coordinates, as well as the sprite variable insert into sprite group. As for pseudocode is as follows
The code at line number 4 is the sprite variable named "Bill_Rizer" with the parameter that contains the directory location of the sprite image, and there are a number of 6.2 on the parameter which means the sprite has 6 rows and 2 columns. In the code I also added a function static coordinates which aims to make the sprite is still at coordinates 50,50 on a games area or the playfield as seen on line number 10. After I define a variable that contains the directory sprite. then I added a spritegroup Variable to a method playfield as in lines of code number 12, then I add the sprite variable to the spritegroup method as shown in line number 13.
The entire property of the sprite and background we have the initialization method "initresources ()", to animating sprite we need to specify the index columns frame the picture that would we use for animated sprites.
|
A single strip of Sprite character Bill Rizer in the NES game 3 with the index 6 columns and 2 rows (image source: www.spriters-resource.com) |
For example, I want to display the animation running to the left on the character "bill_rizer". That means we will use an index on the column to column 1 to 6. For the implementation of the programme of the "setAnimationFrame" method inputed as code on the line to 14. on library Golden T Game Engine sprite index calculated from 0, for example for the animation running to the left is the column frame 1 to 6. Because in writing programs, sprite index calculated from 0 then sprite column index is expressed from 0 to 5 (notice the back line to 14) then give it a value of true on two boolean method for animating sprite objects on the game area and repeat simultaneously on the sprite animation as seen on line 15 and 16.