Day 15: Scene Layers


We have implemented sprites so far. In order to create games with our framework, we need to handle sprites in a systematic way. Today we go one more step up the ladder. In a real world game, it matters in what order objects are drawn on the screen. In a 3D game, the distances of objects from the camera (meshes) determine which objects block others. A tree standing right in front of the camera for example, blocks a ball which is right behind it.

Red ball behind the tree

Continue reading

Day 14: Animation Handling

What is an animation?

As the last day of this part, we are going to discuss something more interesting about sprites. What brings sprites to life is them evolving and moving around, and that’s what animations are. Below is a simple example of an animation. The picture below shows an atlas containing 5 different poses of the character “Grace” from the game “Give Me a Kiss!”

Grace Atlas

As you might guess, these frames, when played in the right order, give the impression of her walking. Take a look at the animation below:

Grace Walking

Continue reading

Day 13: Image Sprites – Part 2

Last day we started implementing an “image sprite”. We wrote down the code for extracting a sprite’s animation frames from an atlas. Today use it and complete our image sprite.

Preparing the texture class

If you remember from day 8, our texture class was designed to always draw the whole image resource. But that’s not really handy when it comes to atlases since we need to be able to choose specific parts of a texture to draw. In the same day we defined a field called tempTextureBuffer and filled it manually. It’s now time to drop this field and everything related to it before we can make this class more flexible. So bring your Texture class into view, and omit the following from it:

  • The field tempTextureBuffer
  • The method buildTextureMapping()
  • The three lines from the end of the load method:

    // If texture mapping buffer has not been initialized yet, do it now.
    if(tempTextureBuffer == null)

Continue reading

Day 12: Image Sprites – Part 1


Up to now we have successfully implemented a texture manager to properly load and unload textures when needed. We also implemented the general behavior of a sprite, regardless of its type. Today we are going to implement a common form of sprite, which is called “Image Sprite” in our framework. An image sprite consists of a series of images taken from an atlas, which it uses as frames. Apart from the normal behavior of a sprite, an image sprite can be animated through changing its frames.

Frames and cutouts

Before we begin our image sprite implementation, we need to create a way to take out its frames from a given atlas. For simplicity, we assume that all the frames corresponding to a sprite always stick to each other in the form of a grid, and they are not scattered on the atlas. With this assumption, we can implement a class for this specific purpose: Cutout.

Texture Atlas

Continue reading