footstepmove.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. const { ccclass, property } = cc._decorator;
  8. @ccclass
  9. export default class footstepmove extends cc.Component {
  10. @property(cc.Label)
  11. label: cc.Label = null;
  12. @property
  13. text: string = 'hello';
  14. // LIFE-CYCLE CALLBACKS:
  15. // onLoad () {}
  16. start() {
  17. this.node.on(cc.Node.EventType.TOUCH_START, this.sttt, this);//当手指在背景上移动时触发move事件
  18. this.node.on(cc.Node.EventType.TOUCH_MOVE, this.move, this);//当手指在背景上移动时触发move事件
  19. }
  20. move(event: cc.Event.EventTouch) {//负责移动摇杆 手指移动时调用
  21. // this.node.x += (event.getLocationX() - this.startpos.x) * 0.1
  22. // this.node.y += (event.getLocationY() - this.startpos.y) * 0.1
  23. this.node.x += event.getDeltaX()
  24. this.node.y += event.getDeltaY()
  25. }
  26. sttt(event: cc.Event.EventTouch) {//负责移动摇杆 手指移动时调用
  27. window['selectfootstep'] = this.node
  28. }
  29. // update (dt) {}
  30. }