Blog

Day 16: Scene

Today we finally implement scenes. Scenes are entities that correspond to a single state (screen) in a game. This can be a menu screen, the main game, or credits screen. A game made using Artenus has a single stage, on which scenes are switched to create the flow of the game. Having implemented the building blocks, there is not much work left for us to do today.

Implementing fundamentals

The last day we created sprite collections, which we saw how they are going to act as layers of our scene. So, we start our implementation by plugging them in. Create a class called Scene as a sibling to Stage, and add the following fields to it:

	protected Stage stage;
	private final SpriteCollection[] layers;

As our scene is part of a stage, we need to keep track of the parent for later. That’s what the first field is for. The second field contains an array of sprite collections. When we add a sprite to a scene, we do so by indirectly adding it to one of these layers. We could also use an ArrayList instead of an array. But since the cases where we want to push an extra layer in the middle of a scene are rare (and can almost always be replaced by an improvisation), we stick to the array.

Continue reading

Day 15: Scene Layers

Introduction

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)
    	buildTextureMapping();
    

Continue reading

Day 12: Image Sprites – Part 1

Introduction

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