moveTime.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { GameLogic } from "./GameLogic";
  2. const {ccclass, property} = cc._decorator;
  3. @ccclass
  4. export default class MoveTime extends GameLogic {
  5. private _speed: number = 100;
  6. public get speed(): number {
  7. return this._speed;
  8. }
  9. public set speed(value: number) {
  10. this._speed = value;
  11. }
  12. private _dirction: cc.Vec2 = cc.v2(0, 0);
  13. public get dirction(): cc.Vec2 {
  14. return this._dirction;
  15. }
  16. public set dirction(value: cc.Vec2) {
  17. this._dirction = value;
  18. }
  19. private _overTime: number = 0;
  20. public get overTime(): number {
  21. return this._overTime;
  22. }
  23. public set overTime(value: number) {
  24. this._overTime = value;
  25. }
  26. startTime = 0;
  27. call:Function = null;
  28. gameUpdate(dt: number): void {
  29. this.node.x += this.speed * dt * this.dirction.x;
  30. this.node.y += this.speed * dt * this.dirction.y;
  31. this.startTime += dt;
  32. if(this.startTime >= this._overTime){
  33. this.call && this.call();
  34. this.destroy();
  35. }
  36. }
  37. }