Game Development Reference
In-Depth Information
The preceding code iterates over all the objects, and if the materialFile class
variable is defined from an object, then it sets the value of hasTexture to 1 ( true ).
For active textures, we use a very simple strategy. As an object uses a single texture,
we activate only one texture in the GPU ( gl.activeTexture(gl.TEXTURE0); ).
Then we assign the texture from the textures array of the Stage class to the active
texture buffer. The texture object is retrieved from the stage textures array using the
textureIndex variable . The class variable textureIndex is initialized for each
StageObject that is to be drawn ( stage.textures [stage.stageObjects[i].
textureIndex].texture); ). This texture object is bound to the active texture 0 using
the gl.bindTexture API call. Then, we finally assign the active texture indexed at 0 to
the uniform ( uSampler ).
Well, this is all the update we need to add textures to our scene. Now let's move on
to animations.
Understanding the animation types in
3D games
Animation is about adding something dynamic to our game scene, like moving
objects. Until now, in all our examples, the objects were static. We simply moved
our camera to have a different perspective of the scene, but the objects' location
did not change over time with respect to each other. In this chapter, we will now
move objects at different timings or user-generated events. We will also learn about
chained animations. But before we go ahead, let's learn some basics.
In game development, the most common animation techniques are time-based
animation, tweens (interpolation), and skinned animation using rigged models.
Understanding time-based animation
We will demonstrate a way of running animation and game logic at a constant speed
independent of the effective frame rate. But first, let's understand what frame rate or
frame-based animation is.
Understanding frame-based animation
Frame-based animation is a system in which the game world is updated, one
iteration each frame. This is the easiest system to implement and we used
it in our previous chapters, but it has several drawbacks. The speed of your
game is effectively tied to the frame rate, which means it will run more slowly
(chronologically) on older computers and faster on newer ones. This is not what is
expected. So, let's go over what we did earlier.
 
Search WWH ::




Custom Search