0
Help with Game Dev w/ Js 18.2
Always says null reading 'getContext' not sure why. I did copy it to JS still same result. This what I should input the code; var canvas= document.getElementById ('canvas'); var context= canvas.getcontext('2d'); var x=300; var y=350; context.arc( x, y, 50, 0, 2 * Math.PI); context.fillStyle='red'; context.fill();
7 Respostas
+ 2
'null' is when your running this code before canvas gets loaded
+ 1
So put your code in this :
window.onload() = function() {your code here}
0
I think I know why.
0
I'm still learning, but there was a problem with your solution which is an error according to the app. But the question is, is this wrong?
Window onload()=function() {var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
var x = 300;
var y = 350;
}
context.arc(x, y, 50, 0, 2 * Math.PI);
context.fillStyle="red";
context.fill();
0
Try it in code playground and tell me the error you get
0
Help
0
This not working