Crafty.canvasLayer

Collection of mostly private methods to draw entities on a canvas element.

Methods and Properties

Back to top

Crafty.canvasLayer._canvas

Main Canvas element

Back to top

Crafty.canvasLayer.add

public Crafty.canvasLayer.add(ent)
ent

The entity to add

Add an entity to the list of Canvas objects to draw

Back to top

Crafty.canvasLayer.context

This will return the 2D context of the main canvas element. The value returned from Crafty.canvasLayer._canvas.getContext('2d').

Back to top

Crafty.canvasLayer.drawAll

public Crafty.canvasLayer.drawAll([Object rect])
rect

a rectangular region {_x: x_val, _y: y_val, _w: w_val, _h: h_val}

  • If rect is omitted, redraw within the viewport
  • If rect is provided, redraw within the rect
Back to top

Crafty.canvasLayer.drawDirty

public Crafty.canvasLayer.drawDirty()
  • Triggered by the "RenderScene" event
  • If the number of rects is over 60% of the total number of objects do the naive method redrawing Crafty.canvasLayer.drawAll instead
  • Otherwise, clear the dirty regions, and redraw entities overlapping the dirty regions.

See Also

Back to top

Crafty.canvasLayer.init

public void Crafty.canvasLayer.init(void)

Events

NoCanvas
triggered if `Crafty.support.canvas` is false

Creates a canvas element inside Crafty.stage.elem. Must be called before any entities with the Canvas component can be drawn.

This method will automatically be called if no Crafty.canvasLayer.context is found.