A few days ago I made a northern Iranian dish called Mirza Ghasemi for a friend of mine. They were psyched, and immediately asked for the recipe, so they can cook for their colleagues. When I finished writing the recipe in English, I thought it could be a good idea not only to share it with my friend, but with whoever else who might want to try it. Hence I decided to add a section to my long-abandoned blog for Iranian cuisine.
By now we have the foundation we need to implement our entity-based framework. Today we are going to go through an example of how we can adapt our previous logic to this system. We begin with sprites not only because they constitute one of the key components of Artenus, but also because they are entities that have most of the behaviors we discussed on day 24. What we do today is then basically defining Sprite as a combination of these behaviors rather than a simple object.
Last day we introduced entities. Our implementation for them was extremely general and simple: they had only attach and detach methods. If we want to adapt them to the different scenarios they are meant for, we need another mechanism. In some game engines, this mechanism is called “attachments”. For example, each entity can have a motion attachment, a physics attachment, and so on. In Artenus, we take a different approach, and handle different use cases of entities through behaviors. A behavior is a declaration of a feature or a set of functions an entity supports.
After a relatively long break, we now start the fourth part of the tutorial series! What we designed over the past 3 parts was a simple graphics framework. However, as we all know, there is more to games than graphics. Other elements of games include physics, controls, etc. Today, we discuss a framework that can accommodate all these features.
Last day we started creating an atlas-based font class to draw text. Today we are going to complete this work by using it to draw characters. In order to draw a piece of text on the screen, we need the following information.
- The text (a series of characters)
- Screen coordinates to draw the text
- Font size (and possibly other attributes)
Given font size, we need to scale the atlas texture accordingly before drawing characters. What we introduce later today are text sprites. Like other sprites in our framework, text sprites can be rotated, scaled, and translated. For ease of use, we associate the scaling factor of a text sprite to its font size. For instance if the scaling factor is 12, it represents a text with a font height of 12 pixels. This contrasts with a normal texture, where it means 12 times as big as the original size. In day 6 we discussed how transformations work in OpenGL ES. In order to figure out how we should apply transformations to text sprites, we have to keep the following in mind:
- Rotation should be applied to the text as a whole, not individual characters.
- Scaling can either be applied to the whole text or to individual characters.
- Translation is applied to the whole text as well as individual characters. Note that we have to position the text first, and then every character should appear after the previous.