我使用了一個udemy課程來製作一個簡單的pong遊戲。 我現在正在重新創建它作爲練習,我一直讓錯誤畫布爲空。任何幫助?我的Html畫布爲空。真的很煩人
<html>
<canvas id="gamecanvas" width="600" height="800"></canvas>
<script>
var canvas = null;
var Context = null;
window.onload = function(){
canvas.document.getElementById("gamecanvas");
Context.canvas.getContext("2d");
drawEverything();
}
function drawEverything() {
Context.fillStyle = "black";
Context.fillRect(0,0,canvas.width,canvas.height);
Context.fillStyle = "white";
Context.fillRect(0,360,20,80);
Context.fillStyle = "white";
Context.fillRect(580,360,20,80);
Context.fillStyle = "green";
context.beginpath();
context.arc(0,0,10,10,Math.PI*2,true);
context.fill();
}
也許'canvas = document.getElementById(「gamecanvas」)'onload'函數? –
你正在做'canvas.document',所以基本上試圖訪問'null'對象的屬性'document' –
你還會遇到問題,因爲'context!= Context'。 –