Skip to content

Instantly share code, notes, and snippets.

@karlwestin
Created February 9, 2012 12:30
Show Gist options
  • Save karlwestin/1779676 to your computer and use it in GitHub Desktop.
Save karlwestin/1779676 to your computer and use it in GitHub Desktop.
Trying a potention performance improvement in the Actor.animation-function in CAAT
animate : function(director, time) {
// General idea:
// try to touch the DOM as little as possible,
// extra JS calculations much cheaper than extra DOM-settings
if ( !this.isInAnimationFrame(time) ) {
this.inFrame= false;
this.dirty= true;
this.style( 'display', 'none');
return false;
} else {
// Change 1: checking whether visibility has changed before setting
if(this.wasvisible !== this.visible) {
this.style( 'display', this.visible ? 'block' : 'none');
this.wasvisible = this.visible;
}
}
for( var i=0; i<this.behaviorList.length; i++ ) {
this.behaviorList[i].apply(time,this);
}
// Change 2: checking whether opacity has changed before setting
var newAlpha = this.parent ? this.parent.frameAlpha*this.alpha : 1;
if (this.frameAlpha!==newAlpha) {
this.frameAlpha = newAlpha;
this.styleAlpha(this.frameAlpha);
}
this.inFrame= true;
this.setModelViewMatrix(false);
return true;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment