Abstraction layer to do layers on an html canvas element.
Methods:
addLayer( layerObj ) -> add a layer to the canvas. layerObj = { id: whateveryouwant, show: true/false, render: function( canvas, ctx ) {} }
The addLayer method is chainable ... so you can do myCanvas.addLayer( {} ).addLayer( {} ).addLayer( {} );
removeLayer( id ) -> returns false if the id is not found
getLayer( id ) -> returns the layer object, so you can update it.
render() -> once you are ready to draw/redraw call this.
Just include layeredCanvas.js to your page. As in <script src="layeredCanvas.js"></script>
- Make sure your markup has the
<canvas id="theId">
element. - Create the JS object with the id reference:
myLayeredCanvas = new layeredCanvas( "theId" );
- Add the layers with their content:
myLayeredCanvas.addLayer( { id: 'myLayerId', show: true, render: function( canvas, ctx ) { //do the usual canvasy stuff using ctx as context2d or canvas as the actual canvas element } } );
- Call
myLayeredCanvas.render();
Better instructions coming soon!
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
12/20/2015 - First version born