0
私は関数内でループメソッドを呼び出していますが、問題は "ループ"を返す "この関数は、」ここに例を示します"this" returnを使ったプロトタイプ呼び出し関数は "関数ではありません"
window.onload= startGame();
var theGame;
function startGame(){
theGame = new game();
theGame.loop(); /*im calling the method*/
}
function game(){
this.canvas=document.getElementById("breakout");
this.context = this.canvas.getContext('2d');
this.canvas.width=window.innerWidth;
this.canvas.height=window.innerHeight;
// this.loop(); /*¿can i call it here too?*/
this.speed = 100;
}
game.prototype.loop = function() {
console.log(this.speed+=1);
var self = this;
requestAnimationFrame(function(){
self.loop();
});
};
私が呼ぶとき 『』ブラウザのエラー方法 『LOOPをキャッチされない例外TypeError:theGame.loopは関数ではありません』
それは 'window.onload = startGameにする必要がある;'、そこに機能を呼び出すことなく。 – Bergi
機能を早く呼び出すことに関連する問題に関する質問は何度も尋ねられています。私はこのために標準的なQ&Aが必要だと思っています。 –
'game.prototype.loop'を定義した後、' startGame() 'を最後まで移動してください。 – Oriol