diff --git a/cocos2d/core/CCDirector.js b/cocos2d/core/CCDirector.js index c92f763bad..6807c3c503 100644 --- a/cocos2d/core/CCDirector.js +++ b/cocos2d/core/CCDirector.js @@ -492,6 +492,7 @@ cc.Director = Class.extend(/** @lends cc.Director# */{ var persistNodes = cc.game._persistRootNodes; for (var i = 0; i < persistNodes.length; ++i) { var node = persistNodes[i]; + node._parent = null; node.parent = scene; } diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 2ae8ec2837..dbee2bc0c9 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -104,6 +104,13 @@ var EventType = cc.Enum({ * @readonly */ MOUSE_UP: 'mouseup', + /** + * The event type for mouse wheel events, you can use its value directly: 'mousewheel' + * @property MOUSE_WHEEL + * @type {String} + * @readonly + */ + MOUSE_WHEEL: 'mousewheel', }); var _touchEvents = [ @@ -118,6 +125,7 @@ var _mouseEvents = [ EventType.MOUSE_MOVE, EventType.MOUSE_LEAVE, EventType.MOUSE_UP, + EventType.MOUSE_WHEEL, ]; var _touchStartHandler = function (touch, event) { @@ -194,12 +202,22 @@ var _mouseUpHandler = function (event) { event.stopPropagation(); } }; +var _mouseWheelHandler = function (event) { + var pos = event.getLocation(); + var node = this.owner; + + if (node._hitTest(pos, this)) { + event.type = EventType.MOUSE_WHEEL; + node.dispatchEvent(event); + event.stopPropagation(); + } +}; var _searchMaskParent = function (node) { if (cc.Mask) { var index = 0; var mask = null; - for (var curr = node; curr; curr = curr.parent, ++index) { + for (var curr = node; curr && curr instanceof cc.Node; curr = curr.parent, ++index) { mask = curr.getComponent(cc.Mask); if (mask) { return { @@ -863,7 +881,8 @@ var Node = cc.Class({ mask: _searchMaskParent(this), onMouseDown: _mouseDownHandler, onMouseMove: _mouseMoveHandler, - onMouseUp: _mouseUpHandler + onMouseUp: _mouseUpHandler, + onMouseScroll: _mouseWheelHandler, }); cc.eventManager.addListener(this._mouseListener, this); }