Crafty.DrawManager

Crafty.DrawManager

An internal object manage objects to be drawn and implement the best method of drawing in both DOM and canvas

Methods and Properties

Back to top

Crafty.DrawManager.addCanvas

public Crafty.DrawManager.addCanvas(ent)
ent

The entity to add

Add an entity to the list of Canvas objects to draw

Back to top

Crafty.DrawManager.addDom

public Crafty.DrawManager.addDom(ent)
ent

The entity to add

Add an entity to the list of DOM object to draw

Back to top

Crafty.DrawManager.boundingRect

public Crafty.DrawManager.boundingRect(set)
set

Undocumented

  • Calculate the common bounding rect of multiple canvas entities.
  • Returns coords
Back to top

Crafty.DrawManager.debug

public Crafty.DrawManager.debug()
Back to top

Crafty.DrawManager.drawAll

public Crafty.DrawManager.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.DrawManager.mergeSet

public Object Crafty.DrawManager.mergeSet(Object set)
set

an array of rectangular regions

Merge any consecutive, overlapping rects into each other. Its an optimization for the redraw regions.

The order of set isn't strictly meaningful, but overlapping objects will often cause each other to change, and so might be consecutive.

Back to top

Crafty.DrawManager.onScreen

public Crafty.DrawManager.onScreen(Object rect)
rect

A rectangle with field {_x: x_val, _y: y_val, _w: w_val, _h: h_val}

Test if a rectangle is completely in viewport

Back to top

Crafty.DrawManager.renderCanvas

public Crafty.DrawManager.renderCanvas()
  • 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.DrawManager.drawAll
  • Otherwise, clear the dirty regions, and redraw entities overlapping the dirty regions.

See Also

Back to top

Crafty.DrawManager.renderDOM

public Crafty.DrawManager.renderDOM()

When "RenderScene" is triggered, draws all DOM entities that have been flagged

See Also

Back to top

Crafty.DrawManager.total2D

Total number of the entities that have the 2D component.