CanvasRenderer
methodKapi.CanvasRenderer()
You can use Rekapi to render to an HTML5 <canvas>
. The Canvas renderer does a few things:
- It subclasses
Kapi.Actor
asKapi.CanvasActor
. - If the
Kapi
constructor is given a<canvas>
as acontext
, the Canvas renderer attaches an instance ofKapi.CanvasRenderer
to theKapi
instance, namedcanvas
, at initialization time. So: - It maintains a layer list that defines draw order for
Kapi.CanvasActor
s.
// With the Rekapi Canvas renderer loaded
var kapi = new Kapi({ context: document.createElement('canvas') });
kapi.canvas instanceof Kapi.CanvasRenderer; // true
Note: This Kapi.CanvasRenderer
constructor is called for you automatically - there is no need to call it explicitly.
The Canvas renderer adds some new events you can bind to with Kapi#on
(and unbind from with Kapi#off
).
- beforeDraw: Fires just before an actor is drawn to the screen.
- afterDraw: Fires just after an actor is drawn to the screen.
Kapi.CanvasRenderer = function (kapi) {
this.kapi = kapi;
this._drawOrder = [];
this._drawOrderSorter = null;
this._canvasActors = {};
return this;
};
var CanvasRenderer = Kapi.CanvasRenderer;