CountDown.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. start() {
  13. this.imageDisplay = this.node.getChildByPath("countdown_11/countdown_01").getComponent(Sprite);
  14. this.showCountDown();
  15. }
  16. showCountDown(){
  17. tween(this.countdown_12)
  18. .to(this.countdownDuration,{eulerAngles : new Vec3 (0,0,360*4)})
  19. //.call(()=>{this.imageDisplay.enabled = false})
  20. .call(()=>{this.node.destroy()})
  21. .start();
  22. for(let i = 0;i < 4;i++){
  23. this.scheduleOnce(()=>{
  24. this.showImage(i);
  25. },i * this.displayTime)
  26. }
  27. }
  28. showImage(index:number){
  29. this.imageDisplay.spriteFrame = this.images[index];
  30. this.imageDisplay.enabled = true;
  31. }
  32. update(dt: number) {
  33. }
  34. }