Showing posts with label canvas. Show all posts
Showing posts with label canvas. Show all posts

Tuesday, 7 December 2010

html5 canvas speed notes

Setting fill and Stroke style can have a negative performance impact even if you dont use them and are setting them to what they used to be. (Firefox)

ctx.fillStyle
ctx.strokeStyle



Also I can't make dirty rectangles code run as fast as just doing a big clearRect for the whole canvas. This is for frantic - a space invaders style game where nearly every sprite will have moved since the last paint

ctx.clearRect(0,0,width,height);


Drawing text on canvas:
fillText about twice as fast as strokeText

HTML5 Canvas multiple layers

You can use several canvases on top of each other each one with a different zindex attribute and use them as layers.

Nice simple example of multiple canvases

Sunday, 21 November 2010

JS Game programming main loop

Use this piece of JS to repeatedly call update() method every 10ms.

Handy for game loops!

setInterval(update, 10);


http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/

Full breakout game guide with keypress, mouse & animation