何が間違っているのか分かりません。これはまったく新しいサイトで行われているため、キャッシュの問題はなく、javascriptコンソールはエラーを返さない。キャンバスはページ全体に広がり、適切にタグ付けされます。スクリプトは次のとおりです。キャンバスのfillRectが機能していない
<script type = "text/javascript">
var game = document.getElementById("game");
var context = game.getContext("2d");
var gamePieces = []
function gamePiece(width, height, color, x, y){
this.width = width;
this.height = height;
this.x = x;
this.y = y;
update = function(){
context.fillStyle = color;
context.fillRect(this.x, this.y, this.height, this.width);
}
gamePieces[gamePieces.length] = this
}
var p1 = gamePiece(50, 50, "blue", 0, 0);
function update(){
context.clearRect(0, 0, game.width, game.height);
for(var i = 0; i < gamePieces.length; i++){
gamePieces[i].update();
}
}
</script>
「更新」メソッドを 'this'に割り当てておらず、外部からアクセスすることはできません。代わりに 'this.update = function()...'を使用してください。 –
また、cobstructor関数を使用する場合は、新しい<関数名>を使用する必要があります –
これはエラーをスローしないとは思わない –