简单的发送和监听事件
const {ccclass, property} = cc._decorator;

@ccclass
export default class LoadTest extends cc.Component {

    @property(cc.Sprite)
    spr:cc.Sprite = null

    private remoteTex:cc.Texture2D = null

    start () {
        //监听一次事件
        this.spr.node.once("mousedown",this.onMouseClick.bind(this))
        //监听事件
        this.spr.node.on("say",function(msg){
            console.log(msg)
        })
    }

    onMouseClick(event)
    {
        //发射事件
        this.spr.node.emit("say","HelloWrold")
    }

    onDestroy()
    {
        //关闭监听事件
        this.spr.node.off("say")
    }
}


批注 2019-07-15 215516.png


首页 我的博客
粤ICP备17103704号