Talk given at http://jsconf.eu 2009.
You serve up your code gzipped. Your caches are properly configured. Your data (and scripts) are loaded on-demand. That's awesome—so don't stop there. Runtime is another source of slowdowns, and you can learn to conquer those, too.
Learn how to benchmark your code to isolate performance issues, and what to do when you find them. The techniques you'll learn range from the normal (function inlining) to the extreme (unrolling loops).
33. var CAT_DIRECTION = { NONE : 0, LEFT : 1, RIGHT : 2,};
var CatSprite = cc.Sprite.extend({
direction:null, // :CAT_DIRECTION
ctor:function(){ this._super(); },
onEnter:function(){
this._super();
this.direction = CAT_DIRECTION.NONE,
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this, 1,
true);
},
onExit:function () {
this._super();
cc.Director.getInstance().getTouchDispatcher().removeDelegate(this);
},
getRect:function(){
var h = this._rect.size.height;
var w = this._rect.size.width;
var x = this.getPosition().x - (w/2);
var y = this.getPosition().y - (h/2);
return cc.rect( x, y, w, h );
},
13年6月10日月曜日