move.ts 670 B

123456789101112131415161718192021222324252627
  1. const {ccclass, property} = cc._decorator;
  2. @ccclass
  3. export default class move extends cc.Component {
  4. private _speed: number = 100;
  5. public get speed(): number {
  6. return this._speed;
  7. }
  8. public set speed(value: number) {
  9. this._speed = value;
  10. }
  11. private _dirction: cc.Vec2 = cc.v2(0, 0);
  12. public get dirction(): cc.Vec2 {
  13. return this._dirction;
  14. }
  15. public set dirction(value: cc.Vec2) {
  16. this._dirction = value;
  17. }
  18. protected update(dt: number): void {
  19. this.node.x += this.speed * dt * this.dirction.x;
  20. this.node.y += this.speed * dt * this.dirction.y;
  21. }
  22. }