time.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { _decorator, Component, Node, Label } from 'cc';
  2. import { Tools } from './Tools';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('time')
  5. export class time extends Component {
  6. public isStart:boolean =false;
  7. public curTimme:number =0;
  8. public initTimme:number =0;
  9. delta:number = 1;
  10. start() {
  11. }
  12. update(deltaTime: number) {
  13. if(this.isStart){
  14. if(this.delta>=1){
  15. if(this.curTimme<0){
  16. }else{
  17. this.node.getComponent(Label).string = Tools.ms_time(this.curTimme)
  18. this.curTimme-=1;
  19. }
  20. this.delta = 0;
  21. }
  22. this.delta+=deltaTime;
  23. }
  24. }
  25. startAni(_cur:number){
  26. if(this.initTimme!=_cur){
  27. this.initTimme = _cur;
  28. this.curTimme = _cur;
  29. }
  30. if(this.isStart==true){
  31. }else{
  32. this.node.getComponent(Label).string = Tools.ms_time(this.curTimme)
  33. this.initTimme = _cur
  34. // this.isStart = true;
  35. }
  36. }
  37. stopAni(){
  38. this.isStart = false;
  39. }
  40. }