Merge pull request #644 from zilongshanren/improve-button-normal-spriteframe

fix button target spriteframe change issue
This commit is contained in:
Wang Nan
2016-05-06 10:28:09 +08:00
2 changed files with 26 additions and 0 deletions
+20
View File
@@ -314,9 +314,17 @@ var Button = cc.Class({
if (!this.target) {
this.target = this.node;
}
},
onEnable: function () {
if (!CC_EDITOR) {
this._registerEvent();
} else {
this.node.on('spriteframe-changed', function(event) {
if (this.transition === Transition.SPRITE) {
this.normalSprite = event.detail.spriteFrame;
}
}.bind(this));
}
},
@@ -446,6 +454,18 @@ var Button = cc.Class({
onDisable: function() {
this._hovered = false;
this._pressed = false;
if (!CC_EDITOR) {
this.node.off(cc.Node.EventType.TOUCH_START, this._onTouchBegan, this);
this.node.off(cc.Node.EventType.TOUCH_MOVE, this._onTouchMove, this);
this.node.off(cc.Node.EventType.TOUCH_END, this._onTouchEnded, this);
this.node.off(cc.Node.EventType.TOUCH_CANCEL, this._onTouchCancel, this);
this.node.off(cc.Node.EventType.MOUSE_ENTER, this._onMouseMoveIn, this);
this.node.off(cc.Node.EventType.MOUSE_LEAVE, this._onMouseMoveOut, this);
} else {
this.node.off('spriteframe-changed');
}
},
_applyTransition: function (color, sprite) {
+6
View File
@@ -161,9 +161,15 @@ var Sprite = cc.Class({
return this._spriteFrame;
},
set: function (value, force) {
if (this._spriteFrame === value) {
return;
}
var lastSprite = this._spriteFrame;
this._spriteFrame = value;
this._applySpriteFrame(lastSprite);
if (CC_EDITOR) {
this.node.emit('spriteframe-changed', this);
}
},
type: cc.SpriteFrame,
},