CanvasDisplay.prototype.drawBackground = function() {
var view = this.viewport;
var xStart = Math.floor(view.left);
var xEnd = Math.ceil(view.left + view.width);
var yStart = Math.floor(view.top);
var yEnd = Math.ceil(view.top + view.height);
var level = this.level.grid;
for (var y = yStart; y < level.length; y++) {
for (var x = xStart; x < level[y].length; x++) {
var tile = this.level.grid[y][x];
if (tile == null) continue;
var screenX = (x - view.left) * scale;
var screenY = (y - view.top) * scale;
var tilePos = tile == "lava" ? scale : 0;
this.cx.drawImage(otherSprites,
tilePos, 0, scale, scale,
screenX, screenY, scale, scale);
}
}
};
One more time, so much thanks for share your knowledge wit us. I finish all the character between 15-16 and have the game running successful with Canvas :v:
Hi! First i want to give thanks for share your knowledge with us, you are making an amazing work with this book.
But I have been following the character 15-16 of the book and i found some bugs or maybe typos, but none stopped me to continuing.
I have found at this lines
915
-916
that maybe you forgot put the.length
properties in thefor
loop, and then like drawback the background is not drawing the whole tiles around the scene. check out the current code: https://github.com/marijnh/Eloquent-JavaScript/blob/master/16_canvas.txt#L915-L916I have fix it bug in the following code below
One more time, so much thanks for share your knowledge wit us. I finish all the character between 15-16 and have the game running successful with Canvas :v:
![eloquentjavascript-game](https://cloud.githubusercontent.com/assets/410885/3204062/163640f6-eda4-11e3-8d71-0307322a97ba.png)