I tried to make a falling snow in canvas. The code works ok in Chrome but in FF18 nothing is displayed.
When I checked it in console Firebug throws this error:
An invalid or illegal string was specified
var s = flakes[flake].chara;
ctx.fillText(s,flakes[flake].x, flakes[flake].y);
Any Ideas what is wrong with my code?
Also The width of canvas element seems to be too big even though it is specified to be 100%. Why?
var screenH = window.innerHeight;
var screenW = window.innerWidth;
canvas.width = screenW;
canvas.height = screenH;
Move
init();to the bottom of your code and then it will work:Because
screenHis not defined. (Strange…)Demo: http://jsfiddle.net/DerekL/jNf47/
Bonus: Debugging
First, I know one of the variables in
ctx.fillTextis not defined, so I have to find out which one is it:So the problem is in
flakes[flake].y. It seems likeflakes[flake].yis referring toscreenH, so that meansscreenHis the problem. Usually variables have to be defined before you callinit(), so I just moved it to the bottom and it works.