![]() |
|
API >> Tutorials >> Tiles for games >> How to display a simple board?
How to display a simple board?Imagine: you need an engine to display different levels of your arcade game.For example, this level will be the first one of your great game:
First you have to make a little reflexion about your levels, and to draw some examples with your favourite drawing program (This is the easiest way). For your first level, you will obtain this kind of picture:
To represent this in your code, we will use the well know switch on/off for cells. In fact, we will use a 2 dimensions array of Booleans. When a cell needs to be drawn, its value will be true, else, it will be false. For our example, the file Tiles.java contains the array needed to display our level. Now, that we have made a representation of the board, we need to choose or to draw a picture for tiles. We made this little one:
Don't forget, all tiles have the same size.
We will introduce something new, the background image in a playfield. To have a pretty representation, it is recommended to display a background image in a playfield.
You can notice that the size of this picture is exactly the same as the applet's one. To set a background image to the playfield, we only have to use the setBackgroundImage(Image) method like this:
Now that all elements of the puzzle are presented, we will construct the board. For this, we will create a new sprite for each filled cell. The advantage, of using sprites for filled cells, is the ability for your future characters to use collision to move on tiles, but this is another story. In our example, the cell picture is a 16x16 image, therefore each cell have the same size. We will go all over our array of Booleans by steps of 16 pixels for cells. Here is this simple engine:
But do you find this board a little bit uniform?
API >> Tutorials >> Tiles for games >> How to display a simple board?
|