Skip to content

Instantly share code, notes, and snippets.

@mikechambers
Created March 19, 2011 20:38
Show Gist options
  • Save mikechambers/877790 to your computer and use it in GitHub Desktop.
Save mikechambers/877790 to your computer and use it in GitHub Desktop.
Switching between cache states
Circle.prototype._collidingCacheCanvas = null;
Circle.prototype._normalCacheCanvas = null;
Circle.prototype._draw = function()
{
if(this.isColliding)
{
if(this._collidingCacheCanvas)
{
this.cacheCanvas = this._collidingCacheCanvas;
return;
}
}
else
{
if(this._normalCacheCanvas)
{
this.cacheCanvas = this._normalCacheCanvas;
return;
}
}
var g = this.graphics;
g.clear();
g.setStrokeStyle(1);
g.beginStroke("#000000");
if(this.isColliding)
{
g.beginFill("FF0000");
}
else
{
g.beginFill("FFFFFF");
}
g.drawCircle(this.radius, this.radius, this.radius);
this.uncache();
this.cache(-1,-1, this.width + 2, this.height + 2);
if(this.isColliding)
{
this._collidingCacheCanvas = this.cacheCanvas;
}
else
{
this._normalCacheCanvas = this.cacheCanvas;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment