编辑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)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。