Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  87] [ 5]  / answers: 1 / hits: 34715  / 10 Years ago, wed, june 25, 2014, 12:00:00

This is my HTML code, showing the canvas:



 <canvas id=backgroundCanvas width=550 height=600></canvas>
<canvas id=playerCanvas width=550 height=600></canvas
<canvas id=enemiesCanvas width=550 height=600></canvas>


This is where the problem is said to occur:



game.contextBackground = document.getElementById(backgroundCanvas).getContext(2d); // line 32
game.contextPlayer = document.getElementById(playerCanvas).getContext(2d); // line 33
game.contextEnemies = document.getElementById(enemiesCanvas).getContext(2d); // line 34


the error occurs on line 34 where it says:




Uncaught TypeError: Cannot read property 'getContext' of null




any help is much appreciated :)


More From » jquery

 Answers
121

Because you have not closed the canvas mark correctly for playerCanvas:



<canvas id=backgroundCanvas width=550 height=600></canvas>
<canvas id=playerCanvas width=550 height=600></canvas>
<canvas id=enemiesCanvas width=550 height=600></canvas>

[#70430] Tuesday, June 24, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jeremiahianx

Total Points: 629
Total Questions: 106
Total Answers: 112

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
;