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 >> Playfield Scrolling And Pre-Collision mode

What will we do here?

Through an example, we will see how to use pre-collision mode and playfield scrolling.

This tutorial is divided in 3 parts:

Description of the example

The example is composed of a simple labyrinth, and balls with their own behavior. It is a quite simple, but it will cover a large range of games.

The labyrinth

It is composed with simple sprites called Tiles. We used the following image for them:

They are arranged in an array strored in the class Tiles.java, and then it is very easy to dispose them. Here is the playfield with only the labyrinth:

The Java code that disposes sprites in the playfield from the file DisplayTiles.java:


...

    // Disposes tiles from class Tiles
    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);
	  tile.setPosition(x*Tiles.tileSize, y*Tiles.tileSize);
	  playfield.addSprite(tile);
	}
      }
    }

...

 

Balls

A ball is an animated sprite with the right hand behavior (or the left hand to go to the other way). We will see in the next page how to the make the wrapper that moves a ball.
The following image is the sequences pictures of the animation:

 

Now it is time to see what king of rules a ball use to move.

Next Page >>

API >> Tutorials >> Playfield Scrolling And Pre-Collision mode