Game Development Reference
In-Depth Information
The following is an image of the procedurally-generated test sprite:
Each sprite's size is set to 1 x 1 meter. Remember that we defined our visible
world size to be 5 x 5 meters at the beginning of this chapter. So, these sprites will
be exactly one-fifth of the size in our game world. This fact is very important to
understand because it is not the dimension of pixels in your image that defines the
size of your game objects. Everything needs to be defined in virtual meters that relate
to the visible game world.
The origin of the sprite is set to its center point. This allows us to rotate the sprites
around itself without an added translation effect. The position is set randomly between
two meters in negative and positive directions. Additionally, we set the index to 0 (the
first element in the array) for the initially selected sprite. In updateTestObjects() , we
refer to the selected sprite to rotate it on each update cycle. This allows us to easily see
which of the shown sprites is currently the selected one.
All that we have achieved so far is to add the logic to create and modify the game
world with its objects, but none of them are rendered to the screen yet. This is what
we will change next.
First, add one new line to also import the Sprite class in WorldRenderer , as follows:
import com.badlogic.gdx.graphics.g2d.Sprite;
After this, add the following code to WorldRenderer :
public WorldRenderer (WorldController worldController) {
this.worldController = worldController;
init();
}
private void init () {
batch = new SpriteBatch();
camera = new OrthographicCamera(Constants.VIEWPORT_WIDTH,
Constants.VIEWPORT_HEIGHT);
camera.position.set(0, 0, 0);
camera.update();
}
 
Search WWH ::




Custom Search