In the last section of this chapter, we will create an animation effect with textures. We want the grenade to explode once its animation ends. Although explosions in games are created using particle physics, for simple explosions, we chose to confine ourselves to texture animation. So let's first understand what we mean by texture animation.
Until now, we were updating an object's location or rotation in our update
function. In short, we were manipulating the ModelView matrix. Now, we will change the texture in our update
function.
Let's slide back to the start of the chapter where we said that the Stage
class holds the reference to all initialized textures and each StageObject
holds the textureIndex
, the index to the initialized texture. Now, if we change the value of the textureIndex
property in the update call, it will render each time with a different texture, giving an illusion of the animation.