PlayerContorl.ts 610 B

1234567891011121314151617181920212223242526
  1. import { _decorator, Component, EventTouch, Input, input, Node } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('PlayerContorl')
  4. export class PlayerContorl extends Component {
  5. _speed=200;
  6. _initPosX=0;
  7. start() {
  8. this.node.on(Node.EventType.TOUCH_MOVE,this.touchMove,this)
  9. this._initPosX=this.node.position.x;
  10. }
  11. touchMove(event:EventTouch)
  12. {
  13. const delta=event.getDelta()
  14. let pos=this.node.position;
  15. this.node.setPosition( this._initPosX,pos.y+0.01*this._speed*delta.y)
  16. }
  17. update(deltaTime: number) {
  18. }
  19. }