+ 3
how comes when i try using the getContext("2d") ...there is an output of cant get context of null???
ill be glad for your positive response and what i need to have to make games with javascript ..html ...css
2 Answers
+ 7
Please share your code link so we can see what's wrong.
This happens when your code fails in selecting the canvas element.
This may help you:
https://www.sololearn.com/post/90825/?ref=app
But, again, please let us see your code.
+ 3
The <script> you are running probably runs before the document is loaded and your canvas does not exist yet. Try this:
document.addEventListener("DOMContentLoaded", () => {
let mycanvas = document.getElementById("mycanvas");
let ctx = mycanvas.getContext("2d");
... etc etc
});