Skip to content

Canvallax.createElement()

Shaw edited this page Nov 12, 2015 · 1 revision

Create custom element types using Canvallax.createElement(object). The object provided will be added to that element's prototype and inherited by each element of that type.

Each element type created should include a render property with a function that will actually draw that element on the canvas.

Example

  Canvallax.RedCircle = Canvallax.createElement({
    fill: '#F00',
    size: 30,
    render: function(ctx) {
      ctx.beginPath();
      ctx.arc(this.x + this.size, this.y + this.size, this.size, 0, twoPI);
      ctx.closePath();
    }
  });
  
Clone this wiki locally