当前位置:网站首页>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
边栏推荐
猜你喜欢

整理混乱的头文件,我用include what you use

Smart Logistics Park supply chain management system solution: digital intelligent supply chain enables a new supply chain model for the logistics transportation industry

Understand ThreadLocal in one picture

World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection

Hidden corners of coder Edition: five things that developers hate most

建筑建材行业经销商协同系统解决方案:赋能企业构建核心竞争力

Kunming Third Ring Road Closure project will pass through these places. Is there one near your home?

Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure

Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?

整理混乱的头文件,我用include what you use
随机推荐
被PMP考试“折磨”出来的考试心得,值得你一览
整理混乱的头文件,我用include what you use
网页游戏引擎
ble HCI 流控机制
图像检索(image retrieval)
PingCode 性能测试之负载测试实践
Go micro tutorial - Chapter 2 go micro V3 using gin and etcd
[acwing] 58 weeks 4489 Longest subsequence
缓存穿透、缓存击穿、缓存雪崩分别是什么
Is it safe for CITIC Securities to open an account online? Is the account opening fee charged
照明行业S2B2B解决方案:高效赋能产业供应链,提升企业经济效益
kaili不能输入中文怎么办???
完美融入 Win11 风格,微软全新 OneDrive 客户端抢先看
一加10 Pro和iPhone 13怎么选?
【模板】【luogu P4630】Duathlon 铁人两项(圆方树)
昆明三环闭合工程将经过这些地方,有在你家附近的吗?
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业
Ble HCI flow control mechanism
Is it safe for Bank of China Securities to open an account online?
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!