zoukankan      html  css  js  c++  java
  • Cocos Creator cc.Event点击触摸事件详解

    cc.Event事件
    请不要直接创建 cc.Event 对象,因为它是一个抽象类,请创建 cc.Event.EventCustom 对象来进行派发。

    cc.Class({
    extends: cc.Component,
    _sayHello: function () { console.log('Hello World'); },
    onEnable: function () {
    this.node.on('foobar', this._sayHello, this); //添加事件
    },
    onDisable: function () {
    this.node.off('foobar', this._sayHello, this); //删除事件
    },
    });

    当我们从节点 c 发送事件 “foobar”,倘若节点 a,b 均做了 “foobar” 事件的监听,则 事件会经由 c 依次传递给 b,a 节点。如:

    // 节点 c 的组件脚本中
    this.node.dispatchEvent( new cc.Event.EventCustom('foobar', true) );
    如果我们希望在 b 节点截获事件后就不再将事件传递,我们可以通过调用 event.stopPropagation() 函数来完成。具体方法如下:

    // 节点 b 的组件脚本中
    this.node.on('foobar', function (event) {
    event.stopPropagation();
    });

  • 相关阅读:
    SpringBoot构建RESTful API
    Zynq7000系列之芯片系统结构概述
    FPGA编程技巧系列之按键边沿检测
    异常处理规范
    接口定义规范
    工具类编写规范
    第三个月
    测试计算器心得
    2015年三月
    第一份工作
  • 原文地址:https://www.cnblogs.com/luorende/p/8403135.html
Copyright © 2011-2022 走看看