Skip to content

Cocos Creator 触摸事件穿透

更新日期:2020-12-26
  • 创建文档:2020-12-26

触摸事件

假设给整个Canvas添加了事件监听。用网页模拟时,鼠标移动,点击子node都会监听到。

    start() {
        this._cfgTouchField();
    }

    _onTouchFieldDown(e) {
        cc.log('table', '_onTouchFieldDown');
    }

    _onTouchFieldMove(e) {
        cc.log('table', '_onTouchFieldMove');
    }

    _onTouchFieldEnd(e) {
        cc.log('table', '_onTouchFieldEnd');
    }

    _cfgTouchField() {
        this.node.on(cc.Node.EventType.MOUSE_DOWN, this._onTouchFieldDown, this);
        this.node.on(cc.Node.EventType.MOUSE_MOVE, this._onTouchFieldMove, this);
        this.node.on(cc.Node.EventType.MOUSE_LEAVE, this._onTouchFieldEnd, this);
        this.node.on(cc.Node.EventType.MOUSE_UP, this._onTouchFieldEnd, this);
    }

网页模拟,鼠标从空白地方移入Toggle的范围时,会触发一次cc.Node.EventType.MOUSE_LEAVE; 然后又是cc.Node.EventType.MOUSE_MOVE

作者: rustfisher.com | rf.cs@foxmail.com
示例: AndroidTutorial Gitee, Tutorial Github
本文链接: https://www.an.rustfisher.com/cocos/creator/ccc-touch-event/
一家之言,仅当抛砖引玉。如有错漏,还请指出。如果喜欢本站的内容,还请支持作者。也可点击1次下方的链接(链接内容与本站无关),谢谢支持服务器