Game Development Reference
In-Depth Information
Figure 8-17. The static models of the explosion effect. The spark model is a collection of thin triangles in random
lengths and orientation that are all on the same plane. The ring model is a just a round triangle strip. These models are
generated in the initialization of the game.
Initialization of the sound module with the files loaded by the <audio> tags. The sound module is
quite simple, but is outside the scope of this chapter.
First call to tick() to start the animation engine.
Setting up a timed event with setInterval() for the appearance and disappearance of bonus
objects on the grid. The interval is set to 1 second and in each call, the game randomly decides if
it's time for a bonus to appear or not.
Finally, a call is made to the 2D graphics module to display the main starting menu of the game
on the 2D canvas. Aside from displaying the start menu and setting up keyboard and mouse
controls for it, this function also starts an asynchronous download of the grid model of the first
level. This action happens here rather than in the main initialization function since the game
possibly needs to load these models each time the main menu is reached.
webGLStart() returns rather quickly, but the events and timers it established will drive the game from here
on. The majority of the functionality originates in the tick() function.
The tick() function
The tick() function is called repeatedly by the JavaScript runtime in response to repeat calls to
requestAnimationFrame() . The calls to tick() continue the entire time the game is running, without
exception, even when it is paused or a 2D menu is shown. When no 3D content needs to be visible, the
function just skips over the scene-rendering phase. In practice, the situation where absolutely no 3D
content is shown happens only when the main menu of the game is active. At any other time, there is
 
Search WWH ::




Custom Search