CocosCreator全域性訊息事件

2021-09-24 20:03:39 字數 1007 閱讀 3704

我的git有**,如下:

notificationcenter.ts

import

from

"./notificationname"

;/**

* cocoscreator's global event/message center.

*/export

class

notificationcenter

return

this

.instance;

}/**

* listen to a notification

* @param name

* @param callback

*/public

on(name: notificationname, callback: function, target?

: any)

/** * dispatch a notification

* @param name

*/public

emit

(name: notificationname, arg1?

: any, arg2?

: any, arg3?

: any, arg4?

: any, arg5?

: any)

/** * cancel listen

* @param name

*/public

off(name: notificationname, callback?

: function, target?

: any)

}

notificationname.ts

export

enum notificationname

對於非常駐監聽,特別需要注意新增了監聽後,在節點消除的時候需要刪除監聽。防止造成多重監聽。

參考文件:

cocos creator全域性變數與常住節點

1,使用 通過模組訪問 建立乙個helloworld專案。建立乙個指令碼,來儲存變數,common.js module.exports text hello,world use this for initialization onload function 跳轉場景 setscene functio...

cocos creator 十二 問題

1 socket為什麼不能使用 2 cocos類之攝像機使用問題 1 在使用socket為什麼不能使用 if cc.sys.isnative opts this sio window.io connect this.ip opts this sio.on connect function data ...

cocos creator模組簡介

專案 專案設定 選擇將在構建發布時要打包進引擎的模組 模組如下 core 必選 canvas 必選,畫布 sprite 必選,精靈 label 文字控制項 mask 遮罩控制項 ccspritedistortion 扭曲效果元件,用於改變 型別sprite的渲染,只有當sprite元件已經新增後,才...