cocos creator从零开发虚拟摇杆(04)-摇杆事件触发
编辑scripts/JoyStick.ts
,添加handlers
属性。
@property([cc.Component.EventHandler])
private handlers: cc.Component.EventHandler[] = []
private ringNode: cc.Node
修改onTouchMove
方法,结尾处添加如下代码。
const dir = this.dotNode.getPosition().normalize()
this.handlers.forEach(handler => handler.emit([dir]))
this.node.emit('JoyStick', dir)
修改onTouchEnd
方法,结尾处添加如下代码。
this.handlers.forEach(handler => handler.emit([cc.Vec2.ZERO]))
this.node.emit('JoyStick', cc.Vec2.ZERO)
本作品采用《CC 协议》,转载必须注明作者和本文链接