+ 1
Creating games in Java course
Section 12-2 drawing in canvas. I typed the code exactly as written and still get a null error. Getcontext(2b). My red ball will not appear in my game. Does anyone else had this error? The editor gives you a page to add Java is there anything specific I need to put between var? Also has anyone encountered code in the courses being wrong? Thank You
3 Answers
+ 1
I just thought I'd check: you have written Java, and you know that is different from JavaScript, correct?
Can you put the code into a code bit on the code playground and share/insert that here? Make sure, if you're doing JavaScript, that you choose the "Web" option, not the Java one.
0
window.onload = function() { let btn= document.getElementById("Jump"); let count = 0; btn.onclick = function(){count +=1;}
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
<h1 align="center">My Jumper game</h1>
<p align="center">A fun flappy-bird like game</p>
<canvas> id="canvas" width="600" height="400">
Your browser does not support the html5 canvas tag.</canvas>
<button id= "Jump">Jump</button>