Я пытаюсь создать игру на холсте HTML, но получаю следующую ошибку: Ошибка JavaScript: Ошибка типа: undefined не является объектом (оценивающим this.context.clearRect) в строке 24
Здесь происходит ошибка:
var myGameArea = {
canvas : document.createElement("canvas"),
start : function() {
this.canvas.width = 480;
this.canvas.height = 480;
this.context = this.canvas.getContext("2d");
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
this.frameNo = 0;
this.interval = setInterval(updateGameArea, 20);
},
clear : function() {
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
}
}
//update
function startGame() {
myGamePiece = new component(50, 10, "grey", 10, 120);
myAponent = new component(50, 10, "grey", 10, 200);
myScore = new component("30px", "Consolas", "black", 280, 40, "text");
myGameArea.start();
}
Я запускаю свой код, а затем получаю сообщение об ошибке this.context.clearRect(0, 0, this.canvas.width, this.canvas.height)