Canvas basics, tips and tricks . . .
Posted: 08 Nov 2014 05:40
Hi All,
A Baisc Introduction to the Canvas.
The Canvas object in Lemur is a partial implementation of the Html5 Canvas feature.
This means that lots of html Canvas info can be transferred to the Lemur domain, if it is implemented in Lemur.
I will not attempt a full explanation of it all here and now, but rather add stuff to this thread as time goes.
First some general optimisation ideas, gleaned form general Canvas optimisation principles
* Batch Canvas calls together. Rendering is more expensive the drawing paths, so draw multiple lines then render rather then rendering each line as you go.
* Avoid unnecessary changes to the state of the canvas. Try to keep state changes to a minimum. To draw a pinstripe, rather then change color every stripe, draw all stripes of one color then all stripes of another etc.
* Render on demand where possible. All static parts should be rendered once on load. Parts that change only really need to be rendered when they are changing
* Render screen differences only. Similar to above, only render the differences, not the whole screen. This can be leveraged by a technique called redraw regions.
* Use multiple layered canvases for complex projects. Transparency comes in very handy here to composite stuff.
* Probably avoid floating point coordinates and other things where possible for various reasons.
Just a few thoughts gleaned from some general raves, that pretty much hold true for Lemur as well.
I don't always adhere to all of these but they are worth keeping in mind and they should help...
Canvas programming is another sub world with in Lemur where similar things can be achieved in different ways.
Whilst their is no absolute right way to do something, some ways will end up more efficient then others.
Hopefully this thread will help guide us all
A Baisc Introduction to the Canvas.
The Canvas object in Lemur is a partial implementation of the Html5 Canvas feature.
This means that lots of html Canvas info can be transferred to the Lemur domain, if it is implemented in Lemur.
I will not attempt a full explanation of it all here and now, but rather add stuff to this thread as time goes.
First some general optimisation ideas, gleaned form general Canvas optimisation principles
* Batch Canvas calls together. Rendering is more expensive the drawing paths, so draw multiple lines then render rather then rendering each line as you go.
* Avoid unnecessary changes to the state of the canvas. Try to keep state changes to a minimum. To draw a pinstripe, rather then change color every stripe, draw all stripes of one color then all stripes of another etc.
* Render on demand where possible. All static parts should be rendered once on load. Parts that change only really need to be rendered when they are changing
* Render screen differences only. Similar to above, only render the differences, not the whole screen. This can be leveraged by a technique called redraw regions.
* Use multiple layered canvases for complex projects. Transparency comes in very handy here to composite stuff.
* Probably avoid floating point coordinates and other things where possible for various reasons.
Just a few thoughts gleaned from some general raves, that pretty much hold true for Lemur as well.
I don't always adhere to all of these but they are worth keeping in mind and they should help...
Canvas programming is another sub world with in Lemur where similar things can be achieved in different ways.
Whilst their is no absolute right way to do something, some ways will end up more efficient then others.
Hopefully this thread will help guide us all