ippa/jaws — Issue #15: Suboptimal SpriteSheet code
Author: download13
Created: 2011-11-07 03:31:10+00:00
State: open

I was looking through the Jaws code to see how it worked when I noticed that you store sprites as `canvas` elements.

Curious, I wrote a quick test to see what sort of performance each type of `drawImage` will get, and [here](http://jsperf.com/fastest-canvas-drawing/2) are the results. As you can see, canvas is by far the worst performer. The BlobURL method seem to work very well in Chrome, but `createObjectURL` [isn't compatible with all browsers](http://caniuse.com/#search=createobjecturl).

If compatibility doesn't matter as much as speed, you might want to switch to using `createObjectURL`. Otherwise, `data:` URLs are still looking good.

After that, I thought it might be good to look into the performance difference of pre-cutting spritesheets as opposed to just leaving them one image and using `drawImage(Object image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)` to pick out pieces of them at blit-time. Here's that [test](http://jsperf.com/pre-cut-sprites-vs-dynamic-lift) which seems to indicate that it doesn't matter which you use. Since both are the same speed, I would go with the dynamic lift as it doesn't take up extra memory for all the individual sprites, it only needs a reference to the existing spritesheet image asset.