1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| 这里要把swallowTouches设置为true,这样onTouchBegan返回true才能够吞噬触摸,不继续往优先级更低的层传递,从而实现遮挡层。所以 onTouchDispose处理方法不能在onTouchBegan !!! 返回true之前!!!执行。 loadListener : function(){ var listener = cc.EventListener.create({ event : cc.EventListener.TOUCH_ONE_BY_ONE, target : this, swallowTouches : true, onTouchBegan : this.onTouchBegan, onTouchMoved : this.onTouchMoved, onTouchEnded : this.onTouchEnded }); cc.eventManager.addListener(listener, this); }, onTouchBegan: function (touch, event) { var self = this.target; var locationInNode = self.convertToNodeSpace(touch.getLocation()); var size = self.getContentSize(); var rect = cc.rect(0, 0, size.width, size.height); if (!cc.rectContainsPoint(rect, locationInNode)) { return false; } return true;
}, onTouchMoved : function (touch, event) { var self = this.target; }, onTouchEnded : function (touch, event) { var self = this.target;
self.onTouchDispose(); }, onTouchDispose : function(){ }
|