player.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { EventMgr } from "../Script/Core/Base/EventMgr";
  2. import { Roker_End, Roker_Move } from "./eventDef";
  3. import move from "./move";
  4. const {ccclass, property} = cc._decorator;
  5. @ccclass
  6. export default class player extends cc.Component {
  7. /*===========================自动绑定组件开始===========================*/
  8. /*自动生成*/
  9. @property({type:cc.Node, displayName:""})
  10. private $role_node:cc.Node = null;
  11. /*===========================自动绑定组件结束===========================*/
  12. /*===========================自动生成按钮事件开始==========================*/
  13. /*===========================自动生成按钮事件结束==========================*/
  14. moveCpt: move = null;
  15. protected onLoad(): void {
  16. this.moveCpt = this.node.getComponent(move);
  17. if(!this.moveCpt) {
  18. this.moveCpt = this.node.addComponent(move);
  19. }
  20. }
  21. protected onEnable(): void {
  22. EventMgr.inst.on(Roker_Move, this.onRokerMove, this);
  23. EventMgr.inst.on(Roker_End, this.onRokerEnd, this);
  24. }
  25. protected onDisable(): void {
  26. EventMgr.inst.off(Roker_Move, this.onRokerMove, this);
  27. EventMgr.inst.off(Roker_End, this.onRokerEnd, this);
  28. }
  29. onRokerMove(dirction: cc.Vec2){
  30. this.moveCpt.dirction = dirction;
  31. }
  32. onRokerEnd(){
  33. this.moveCpt.dirction = cc.v2(0,0);
  34. }
  35. }