如题


https://docs.cocos.com/creator/api/zh/classes/Node.html#on
你看事件 child-added 和 child-removed 这是不是增删事件
主要需要的是子节点是否有active行为的监听
position-changed 位置变动监听事件, 通过 this.node.on(cc.Node.EventType.POSITION_CHANGED, callback, this); 进行监听。
size-changed 尺寸变动监听事件,通过 this.node.on(cc.Node.EventType.SIZE_CHANGED, callback, this); 进行监听。
anchor-changed 锚点变动监听事件,通过 this.node.on(cc.Node.EventType.ANCHOR_CHANGED, callback, this); 进行监听。
child-added 增加子节点监听事件,通过 this.node.on(cc.Node.EventType.CHILD_ADDED, callback, this); 进行监听。
child-removed 删除子节点监听事件,通过 this.node.on(cc.Node.EventType.CHILD_REMOVED, callback, this); 进行监听。
child-reorder 子节点顺序变动监听事件,通过 this.node.on(cc.Node.EventType.CHILD_REORDER, callback, this); 进行监听。
group-changed 节点分组变动监听事件,通过 this.node.on(cc.Node.EventType.GROUP_CHANGED, callback, this); 进行监听。
active-in-hierarchy-changed 注意:此节点激活时,此事件仅从最顶部的节点发出。
最后这个不太明白
我觉得你可以父节点监听一个自定义事件 parent.on(‘child_active’,(data)=>{});
子节点发生active行为时,紧接着child.emit(‘child_active’, data); data 传 true 或 false 表示子节点的行为或者其他数据
https://docs.cocos.com/creator/manual/zh/scripting/events.html
你还是看文档用 派送事件 dispatchEvent
我上面的emit只能给自身node发事件