zoukankan      html  css  js  c++  java
  • cocos2d-js 遮挡层

    cc.ModelLayerColor = cc.LayerColor.extend({
      m_touchListener:null,
      ctor:function(){
        this._super();
        var touchListener = {
          event: cc.EventListener.TOUCH_ONE_BY_ONE,
          swallowTouches: true,
          onTouchBegan: this.onTouchBegan
        };
        cc.eventManager.addListener(touchListener, this);
        this.m_touchListener = touchListener;
      },
      onTouchBegan:function(touch, event) {
        var target = event.getCurrentTarget();
        if(!target.isVisible() || (!this.isTouchInside(target,touch))){
          return false;
        }
        return true;
      },
      isTouchInside: function (owner,touch) {
        if(!owner || !owner.getParent()){
          return false;
        }
        var touchLocation = touch.getLocation(); // Get the touch position
        touchLocation = owner.getParent().convertToNodeSpace(touchLocation);
        return cc.rectContainsPoint(owner.getBoundingBox(), touchLocation);
      }
    });
    这里要把swallowTouches设置为true,这样onTouchBegan返回true才能够吞噬触摸,不继续往优先级更低的层传递,从而实现遮挡层。
  • 相关阅读:
    REYES is working now!
    New Caching Mechanism
    Minimum Platform Requirements
    Multithreading Problem with Max SDK
    Bezier Triangles and NPatches
    elvish ray 0.5 beta History
    1.md
    Linux时间同步.md
    好久没写东西了
    从java到c# .net的转变(1)
  • 原文地址:https://www.cnblogs.com/guangyun/p/9045712.html
Copyright © 2011-2022 走看看