当前位置:网站首页>Cocoscreator event dispatch use
Cocoscreator event dispatch use
2022-07-04 17:30:00 【RemoteDev】
1. Event dispatch event mechanism : Based on the event bubble , From the bottom node , Distribute it layer by layer
Such as the current node A Yes 1 Word node , Has child nodes B, and B Nodes have child nodes C
Then the distribution direction of the event is C--->B--->A

Child node C Dispatch incident XXX, Its father's Day B Get the event first XXX control power , Deal with the incident , Then send it to B Parent node A, It can also be dispensed , Call directly
event.propagationStopped = true;To stop event delivery . such A The node will not receive XXX event .
Node dispatch events : this.node.dispatchEvent( Here you pass in the custom event class )
For the custom event class, refer to the following code :
// Event from cc Module import
import { Event } from 'cc';
// Class inheritance Event
class MyEvent extends Event {
// Pass in the event name and bubble parameter when constructing , The last parameter is the additional information of the event
constructor(name: string, bubbles?: boolean, detail?: any) {
super(name, bubbles);
this.detail = detail;
}
public detail: any = null; // Custom properties
}Example of node event dispatch : this.node.dispatchEvent(new MyEvent('XXX',true,' Event additional messages '));
2. Dispatch event handling : Call directly on To deal with it
Call on the upper node of the dispatch event node on(' Event name ',( Event object )=>{});

Dispatch event processing example : this.node.on('XXX',(Event:eventObj)=>{});
3. In one sentence, simply understand the event distribution : Child node dispatchEvent Parent node on
边栏推荐
- 中银证券网上开户安全吗?
- Web game engine
- With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games
- Is it safe for Bank of China Securities to open an account online?
- tp配置多数据库
- TP configuring multiple databases
- 电子元器件B2B商城系统开发:赋能企业构建进销存标准化流程实例
- 网页游戏引擎
- ble HCI 流控机制
- 【HCIA持续更新】WLAN概述与基本概念
猜你喜欢

The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online

NFT liquidity market security issues occur frequently - Analysis of the black incident of NFT trading platform quixotic

智慧物流園區供應鏈管理系統解决方案:數智化供應鏈賦能物流運輸行業供應鏈新模式

被PMP考试“折磨”出来的考试心得,值得你一览

一加10 Pro和iPhone 13怎么选?

7 RSA密码体制

La 18e Conférence internationale de l'IET sur le transport d'électricité en courant alternatif et en courant continu (acdc2022) s'est tenue avec succès en ligne.

CocosCreator事件派发使用

【华为HCIA持续更新】SDN与FVC

整理混乱的头文件,我用include what you use
随机推荐
Image retrieval
Internet addiction changes brain structure: language function is affected, making people unable to speak neatly
长城证券开户安全吗 证券账户怎么开通
Leetcode list summary
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
安信证券属于什么档次 开户安全吗
如何实现一个延时队列 ?
矿产行业商业供应链协同系统解决方案:构建数智化供应链平台,保障矿产资源安全供应
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
Solution of commercial supply chain coordination system in the mineral industry: build a digital intelligent supply chain platform to ensure the safe supply of mineral resources
The test experience "tortured" by the PMP test is worth your review
How to implement a delay queue?
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
R language plot visualization: plot visualization of multiple variable violin plot in R with plot
S2b2b solution for lighting industry: efficiently enable the industrial supply chain and improve the economic benefits of enterprises
Rebalance operation in spark and its difference from repartition operation
Hidden corners of coder Edition: five things that developers hate most
ECCV 2022 released: 1629 papers were selected, and the employment rate was less than 20%
Web game engine
The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online