CountDown.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { _decorator, Component, Node, SpriteFrame, tween, Vec3 ,Sprite,Prefab} from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('CountDown')
  4. export class CountDown extends Component {
  5. @property(Node)
  6. countdown_12:Node = null;
  7. @property([SpriteFrame])
  8. images:SpriteFrame[] = [];
  9. imageDisplay:Sprite = null;
  10. countdownDuration:number = 4;
  11. displayTime:number = 1;
  12. isOver:boolean = false;
  13. start() {
  14. this.imageDisplay = this.node.getChildByPath("countdown_11/countdown_01").getComponent(Sprite);
  15. this.showCountDown();
  16. }
  17. showCountDown(){
  18. tween(this.countdown_12)
  19. .to(this.countdownDuration,{eulerAngles : new Vec3 (0,0,360*4)})
  20. //.call(()=>{this.imageDisplay.enabled = false})
  21. .call(()=>{this.isOver = true ; this.node.destroy()})
  22. .start();
  23. for(let i = 0;i < 4;i++){
  24. this.scheduleOnce(()=>{
  25. this.showImage(i);
  26. },i * this.displayTime)
  27. }
  28. }
  29. showImage(index:number){
  30. this.imageDisplay.spriteFrame = this.images[index];
  31. this.imageDisplay.enabled = true;
  32. }
  33. update(dt: number) {
  34. }
  35. }