Well I haven’t posted in this thread for a while!
Today I’m proud to present to you the new and improved Spritesheet class! Well what does it do, you may ask? Its simple really! First, you obtain or create a spritesheet, then you create a special text file that is parsed by MERCury in a specific and secret way. The information in that file is then used to split up the spritesheet into renderable sub-textures so that you (the MERCury user!) can use spritesheets with style and efficiency. But what’s the best part about the new Spritesheet class? Well, read on to find out more!
First lets talk about Spritesheets. Basically, you need two files. A image file (your spritesheet), and a specially designed text file. Lets take a look at the code:
sheet = Spritesheet.loadSheet(Loader.loadFromClasspath("com/radirius/merc/test/tiles.txt"), Loader.streamFromClasspath("com/radirius/merc/test/tiles.png"));
This line of code simply loads a spritesheet. The two parameters are the “special text file”, and the spritesheet image file, respectively. After you have done this, you can render a sub-texture from that spritesheet like so:
g.drawTexture(sheet.getTexture("Grass"), 10, 10, 128, 128);
Incredibly easy! Now lets look at the special text file:
HEADER 16
Void 0 0
Grass 1 0
Lets break this down.
HEADER 16 basically means that on one side of the spritesheet, we have 16 sub-textures. Its VERY important you have a “square” spritesheet with the same width and height or else the entire Spritesheet class will fail
Void 0 0
“Void” is the name of the tile. 0 0 specifies that the sub-texture resides at position 0, 0 in the spritesheet. Positions are counted in increments of 1. Take a look at this example spritesheet:
The Grass tile is at (according to our special text file) position 1, 0. On the actual spritesheet you can see that the grass tile (the green square) is 1 tile over from the origin (in the top left hand corner). So, logically, the stone tile (the grey square) would be at position 2, 0.
I will develop a GUI based tool that will speed up the process of creating these special text files, but for now they have to be created by hand! I am also aiming to support non-square sub-textures, but that will be down the road.
On another note, I have also added the basics of IO with text files! More on that later though when it is actually complete.
-Team Radirius (we have a new team name!)