Game Development Reference
In-Depth Information
Again, pay attention to the order in which you draw the sprites.
You can also draw multiple moving sprites at the same time. For each balloon, you can define its
own position variable, which is updated in the update method:
Game.update = function () {
var d = new Date();
Game.balloonPosition1.x = d.getTime() % Game.canvas.width;
Game.balloonPosition2.x = (d.getTime() + 100) % Game.canvas.width;
Game.balloonPosition3.x = (d.getTime() + 200) % Game.canvas.width;
};
And in the draw method, you use these positions to draw moving and static balloons at the same time:
Game.draw = function () {
Game.drawImage(Game.backgroundSprite, Game.balloonPosition1);
Game.drawImage(Game.balloonSprite, Game.balloonPosition2);
Game.drawImage(Game.balloonSprite, Game.balloonPosition3);
Game.drawImage(Game.balloonSprite, { x : 200, y : 0 });
Game.drawImage(Game.balloonSprite, { x : 0, y : 300 });
Game.drawImage(Game.balloonSprite, { x : 200, y : 300 });
};
Play around with the example. Think of different ways to draw moving balloons on the screen.
Try a few different position values. Can you let some balloons move faster or slower than others?
Music and Sounds
Another type of commonly used game asset is sound . Most games contain sound effects and
background music. These are important for various reasons. Sound effects give important cues to
indicate to the user that something has happened. For example, playing a click sound when the user
clicks a button provides feedback to the user that the button was indeed pressed. Hearing footsteps
indicates that enemies might be nearby, even though the player may not see them yet. And hearing
a bell ringing in the distance can give an indication that something is about to happen. The old game
Myst was a classic in this respect because many cues about how to progress were passed to the
player through sounds.
Atmospheric sound effects like dripping water, wind in the trees, and the sound of cars in the
distance enhance the experience and give a feeling of being present in the game world. They make
the environment more alive, even when nothing is actually happening on the screen.
 
Search WWH ::




Custom Search