Rectangle is drawn on canvas but instantly disappears

91 Views Asked by At

So I'm doing a project and I'm developing a fall down type game.

The problem seems to be on this line: createRect(20, 40, 25, 15, "red");

It looks like the rect is drawn but instantly disappears any idea on how to fix this? I'm not sure why this happens and I'm learning javascript so I don't have the experience to understand why this occurs

1

There are 1 best solutions below

1
On BEST ANSWER

The problem is that you keep resetting the cavas size several times a second:

setInterval(function(){
    canvas.width = 360;
    canvas.height = 640;
    createMenu();
}, 1000 / fps);

Resetting the size is a (bad) way to clear the canvas (see How to clear the canvas for redrawing), and thus the newly drawn rectangle disappears.