Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Next up, we are going to look at how we can keep track of player
stats such as the time it took to complete a level, total number of kills,
and how many times the player died. Instead of making this screen a
separate game class, we are going to build it into our MyGame class.
We are going to need to add impact.timer to the requires block of our MyGame class. Add the following properties to
the MyGame class:
statText: new ig.Font( 'media/04b03.font.png' ),
showStats: false,
statMatte: new ig.Image('media/stat-matte.png'),
levelTimer: new ig.Timer(),
levelExit: null,
stats: {time: 0, kills: 0, deaths: 0},
The following properties will allow us to track the visibility of
the stats display, an image we can use to mask the screen, a font, a
timer, and a stats object. Next, we are going to need to override the
loadLevel() method so we can start a
timer to track how long it takes the player to complete the level: