当前位置:网站首页>CocosCreator事件派發使用
CocosCreator事件派發使用
2022-07-04 17:30:00 【RemoteDev】
1. 事件派發事件機制: 基於事件冒泡,由最底層節點,層層向上派發
如當前節點A有1個字節點,有子節點B,而B節點又有子節點C
那麼事件派發方向為 C--->B--->A
子節點C派發事件XXX,其父節B先獲得事件XXX控制權,處理該事件,然後再派發給B的父節點A,也可不派發,直接調用
event.propagationStopped = true;
來停止事件傳遞.這樣A節點就不會收到XXX事件.
節點派發事件: this.node.dispatchEvent(這裏傳入自定義事件類)
自定義事件類參考下面代碼:
// Event 由 cc 模塊導入
import { Event } from 'cc';
//類繼承Event
class MyEvent extends Event {
//構造時傳入事件名與是否冒泡參數,最後一個參數是事件附加信息
constructor(name: string, bubbles?: boolean, detail?: any) {
super(name, bubbles);
this.detail = detail;
}
public detail: any = null; // 自定義的屬性
}
節點事件派發示例 : this.node.dispatchEvent(new MyEvent('XXX',true,'事件附加消息'));
2.派發事件處理: 直接調用on來處理
在派發事件節點的上層節點調用on('事件名',(事件對象)=>{});
派發事件處理示例: this.node.on('XXX',(Event:eventObj)=>{});
3. 一句話簡單理解事件派發: 子節點 dispatchEvent 父節點on
边栏推荐
- 线性时间排序
- [glide] cache implementation - memory and disk cache
- Firewall basic transparent mode deployment and dual machine hot standby
- 金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
- 防火墙基础透明模式部署和双机热备
- Ble HCI flow control mechanism
- "Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
- PingCode 性能测试之负载测试实践
- Go micro tutorial - Chapter 2 go micro V3 using gin and etcd
- go-micro教程 — 第二章 go-micro v3 使用Gin、Etcd
猜你喜欢
KS007基于JSP实现人个人博客系统
C# 更加优质的操作MongoDB数据库
【云原生】服务网格是什么“格”?
The winning rate against people is 84%, and deepmind AI has reached the level of human experts in army chess for the first time
Analysis of abnormal frequency of minor GC in container environment
智慧物流园区供应链管理系统解决方案:数智化供应链赋能物流运输行业供应链新模式
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
Congratulations to Mr. Zhang Pengfei, chief data scientist of artefact, for winning the campaign Asia tech MVP 2022
Offline and open source version of notation -- comprehensive evaluation of note taking software anytype
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
随机推荐
【华为HCIA持续更新】SDN与FVC
容器环境minor gc异常频繁分析
第十八届IET交直流输电国际会议(ACDC2022)于线上成功举办
祝贺Artefact首席数据科学家张鹏飞先生荣获 Campaign Asia Tech MVP 2022
To sort out messy header files, I use include what you use
动态规划股票问题对比
手里10万元存款买什么理财产品收益最高?
Is it safe for Great Wall Securities to open an account? How to open a securities account
【测试开发】软件测试——基础篇
《吐血整理》保姆级系列教程-玩转Fiddler抓包教程(2)-初识Fiddler让你理性认识一下
The test experience "tortured" by the PMP test is worth your review
基于wifi控制的51单片机温度报警器
How to "use" Perl modules in directories that are not in @inc- How do I 'use' a Perl module in a directory not in @INC?
Vb无法访问数据库stocks
Solution of dealer collaboration system in building materials industry: empowering enterprises to build core competitiveness
To sort out messy header files, I use include what you use
Implementation of super large-scale warehouse clusters in large commercial banks
C# 更加优质的操作MongoDB数据库
智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式
Rebalance operation in spark and its difference from repartition operation