Book Image

WebGL Game Development

By : Sumeet Arora
Book Image

WebGL Game Development

By: Sumeet Arora

Overview of this book

<p>WebGL, the web implementation of Open GL, is a JavaScript API used to render interactive 3D graphics within any compatible web browser, without the need for plugins. It helps you create detailed, high-quality graphical 3D objects easily. WebGL elements can be mixed with other HTML elements and composites to create high-quality, interactive, creative, innovative graphical 3D objects.</p> <p>This book begins with collecting coins in Super Mario, killing soldiers in Contra, and then quickly evolves to working out strategies in World of Warcraft. You will be guided through creating animated characters, image processing, and adding effects as part of the web page canvas to the 2D/3D graphics. Pour life into your gaming characters and learn how to create special effects seen in the most powerful 3D games. Each chapter begins by showing you the underlying mathematics and its programmatic implementation, ending with the creation of a complete game scene to build a wonderful virtual world.</p>
Table of Contents (17 chapters)
WebGL Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using texture animation for an explosion effect


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.

Let's look at textures, shown in the following...