LoginSignup
2
0

More than 3 years have passed since last update.

CocosCreatorでタッチを透過させる (swallowTouchesをfalseにする) 方法

Last updated at Posted at 2018-10-19

CocosCreatorの(タッチ)イベント登録について

非公開Apiを用いて設定する

どうにもならないので、昔公開されていた非公開のApiを使用して設定しました
TypeScriptで書いてるので必要に応じてJSに戻すなどしてください

const listener1 = cc.EventListener.create({
    event: cc.EventListener.TOUCH_ONE_BY_ONE,
    swallowTouches: false,
    onTouchBegan: (touch: cc.Touch, event) => {
        // Node内をtapしているかでtrue/false切り替えても良い
        return true;
    },
    onTouchEnded: (touch, event) => {
        // 発火した上で透過させたい処理
    }
});
cc.eventManager.addListener(listener1, this.touchNode);

非公開なので、 EventListener や eventManager部分が赤くなったり下記警告が出力されます。

Simulator: JS: [WARN]: The 'cc.eventManager' will be removed in v2.0, please use 'cc.EventTarget or cc.systemEvent' instead.

公式も明確に cc.eventManager を使わないでくれと言っています
- http://docs.cocos2d-x.org/creator/api/en/classes/Node.html#on
- It's the recommended way to register touch/mouse event for Node,
please do not use cc.eventManager directly for Node.

いつ使えなくなるかはわかりませんが現状の対応ということで

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0