Skip to content
何波 edited this page Mar 1, 2019 · 5 revisions

autoClear:true

Indicates whether the stage should automatically clear the canvas before each render. You can set this to false to manually control clearing (for generative art, or when pointing multiple stages at the same canvas for example).

var stage = new createjs.Stage("canvasId");
stage.autoClear = false;
p.update = function(props) {
  if (!this.canvas) { return; }
  if (this.tickOnUpdate) { this.tick(props); }
  if (this.dispatchEvent("drawstart", false, true) === false) { return; }
  createjs.DisplayObject._snapToPixelEnabled = this.snapToPixelEnabled;
  var r = this.drawRect, ctx = this.canvas.getContext("2d");
  ctx.setTransform(1, 0, 0, 1, 0, 0);

  if (this.autoClear) { // 在render前自动清除canvas
    if (r) { ctx.clearRect(r.x, r.y, r.width, r.height); }
    else { ctx.clearRect(0, 0, this.canvas.width+1, this.canvas.height+1); }
  }

  ctx.save();
  if (this.drawRect) {
    ctx.beginPath();
    ctx.rect(r.x, r.y, r.width, r.height);
    ctx.clip();
  }
  this.updateContext(ctx);
  this.draw(ctx, false);
  ctx.restore();
  this.dispatchEvent("drawend");
};

Clone this wiki locally