mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 16:52:43 +08:00
Merge pull request #1058 from pandamicro/v1.2
Delay pause inactive target when adding touch/mouse listener to Node
This commit is contained in:
@@ -1103,6 +1103,7 @@ var Node = cc.Class({
|
||||
* node.on(cc.Node.EventType.TOUCH_CANCEL, callback, this.node);
|
||||
*/
|
||||
on: function (type, callback, target, useCapture) {
|
||||
var newAdded = false;
|
||||
if (_touchEvents.indexOf(type) !== -1) {
|
||||
if (!this._touchListener) {
|
||||
this._touchListener = cc.EventListener.create({
|
||||
@@ -1118,6 +1119,7 @@ var Node = cc.Class({
|
||||
this._touchListener.retain();
|
||||
}
|
||||
cc.eventManager.addListener(this._touchListener, this);
|
||||
newAdded = true;
|
||||
}
|
||||
}
|
||||
else if (_mouseEvents.indexOf(type) !== -1) {
|
||||
@@ -1136,8 +1138,17 @@ var Node = cc.Class({
|
||||
this._mouseListener.retain();
|
||||
}
|
||||
cc.eventManager.addListener(this._mouseListener, this);
|
||||
newAdded = true;
|
||||
}
|
||||
}
|
||||
if (newAdded && !this._activeInHierarchy) {
|
||||
cc.director.getScheduler().schedule(function() {
|
||||
if (this._activeInHierarchy) {
|
||||
cc.eventManager.pauseTarget(this);
|
||||
}
|
||||
}, this, 0, 0, 0, false);
|
||||
}
|
||||
|
||||
this._EventTargetOn(type, callback, target, useCapture);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user