Reputation: 478
I'm not sure how this would work for making a 2D game, I need to draw a Rectangle
and am not sure why it isn't showing up. I have the canvas
display:
set to none
but after running a function it is changed to display of block, so I'm not sure if that would interfere with it or not. Anyway, here is the code:
var gameContext = canvas.getContext("2d");
function draw() {
gameContext.beginPath();
gameContext.lineWidth="6";
gameContext.strokeStyle="red";
gameContext.rect(5,5,290,140);
gameContext.stroke();
}
draw();
Thanks for any help at all, it helps a lot!
Upvotes: 0
Views: 43
Reputation: 627
I don't see any problem with the code you have posted. In fact I ran it myself and it worked fine. Changing the display property shouldn't affect it either. Perhaps try putting a border around the canvas so you're sure the element is visible, e.g.
<canvas style="border: 2px solid black;"/>
Upvotes: 1