I compared your example with this:
http://jsfiddle.net/sPm3b/6/
And it works very fast in Firefox and Chrome.
So we know that the problem is with the images.
You need to optimize how they are created and loaded. Right now, every clear() creating a new image and waiting for it to load! This image should only be created once, in your loadGame() , and then reused over and over again.
Same thing with letterImg in DrawRain() . Move its creation to loadGame()
This will probably fix the problem.
EDIT:
like this:
At the top add:
var letterImg = new Image(); var bgImg = new Image();
Then
function loadGame() { canvas = document.getElementById("gameCanvas"); context = canvas.getContext("2d"); canvas.width = canvasWidth; canvas.height = canvasHeight; bgImg.src = "images/bg.png"; letterImg.src = "images/raindrop.gif";
Then drawRain, for example, would look like this:
var DrawRain = function() { for (i = 0; i < 10; i++) { thisXPos = rain[i][0]; thisYPos = rain[i][1]; context.drawImage(letterImg, thisXPosX, thisYPos);
source share