The Java Game Framework.

Examples, tutorials, documentation and download of the Genuts Framework.
Games made with the Genuts Frameworks.
General articles around games.
Links covering all needs around game dev.
Who are we?
Terms of Service

API >> Tutorials >> Tiles for games >> Non-uniform effect

How to give a non-uniform effect to a simple board?

We use, in this example, the previous one, but we will modify a little the construction engine to break the uniformity of the board. We obtain this:

The principle is one more time very simple. Instead of one picture for tiles, we use 4 different images. There closely have the same representation, but the difference between them give this non-uniform effect:

Random tile image Random tile image Random tile image Random tile image

The size of this images is always the same: 16x16.

Now in our engine, when we display a tile, we choose on of the four pictures for the sprite. To make the code easiest to use, we placed the four images in an array and we use the Math.random() method to choose a random index of the array. Here is the new engine code for constructing the game-board (from RandomBoard.java file):


...
    // Display tiles from class Tiles.
    // If the current position in the Tiles array is set to true,
    // a sprite, randomly taken from four ones, is created.
    for (int y = 0; y < Tiles.tiles.length; y++) {
      for (int x = 0; x < Tiles.tiles[y].length; x++) {
	if (Tiles.tiles[y][x]) {
	  Sprite tile = new Sprite(tileImage[((int) (Math.random()*10000)) % 4]);
	  tile.setPosition(x*tileSize, y*tileSize);
	  playfield.addSprite(tile);
	}
      }
    }
...

In the next example, we will see how to generate a complete board with animations.

<< Previous Page Next Page >>

API >> Tutorials >> Tiles for games >> non-uniform effect