Game Development Reference
In-Depth Information
You use braces to define an object literal that has x and y components. As you can see, it's allowed
to define an object in the instruction that calls a method. Alternatively, you can first define an object,
store it in a variable, and then call the drawImage method using that variable:
var balloonPos = {
x : 100,
y : 100
};
Game.drawImage(Game.balloonSprite, balloonPos);
This code does exactly the same thing as the preceding call to drawImage , except it's much longer
to write. You can simply put the drawImage method call in the draw method, and the balloon will be
drawn at the desired position:
Game.draw = function () {
Game.drawImage(Game.balloonSprite, { x : 100, y : 100 });
};
Figure 4-1 shows what the program's output looks like in the browser.
Figure 4-1. Output of the SpriteDrawing program
Again, note that if you tell the browser to draw a sprite at a given position, the top-left part of the
sprite is drawn there.
Search WWH ::




Custom Search