Created
March 19, 2011 20:38
-
-
Save mikechambers/877790 to your computer and use it in GitHub Desktop.
Switching between cache states
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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