I\'m working on a simple JavaScript game using HTML5 canvas. It\'s a very typical game-loop setup involving:
I assume you are calling init() after the onload event of the window object is fired. The problem is, that does not guarantee to you that the image data is actually available at that point. AFAIR it would fire after the images are fetched from the network but then they still need to be decoded.
Your best bet would be to wait for the images' onload event instead.