Хочу написать игру, через prototype, а в консоле ошибка
Код:
;(function(){
let canvas, ctx, width, height;
let Game = function(){
//Подключаюсь к canvas.
canvas = document.getElementById('knight');
ctx = canvas.getContext('2d');
let gameSize = {
};
this.loadGame();
this.knight = new knight();
}
const bg = new Image();
bg.src = "img/bg.png";
Game.prototype.loadGame = function(){
this.knight();
this.draw();
requestAnimationFrame(()=>{
this.loadGame();
});
}
function knight(){
this.size = {x : 150, y : 150};
this.position = {x : 150, y : 150};
}
Game.prototype.knight = function(){
}
Game.prototype.draw = function(){
ctx.fillRect(150, 150, this.size.x, this.size.x)
}
window.onload = function(){
new Game("ctx");
}
})();