MainScene.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { _decorator, Component, director, instantiate, Node, Prefab, resources, Sprite, SpriteFrame, UITransform, Vec3 } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('MainScene')
  4. export class MainScene extends Component {
  5. @property(Prefab)
  6. countDown:Prefab;
  7. countDownTS:any = null;
  8. bg: Node = null;
  9. protected onLoad(){
  10. }
  11. start() {
  12. let countDown = instantiate(this.countDown);
  13. this.node.addChild(countDown);
  14. //获取倒计时预制体脚本
  15. this.countDownTS = countDown.getComponent("CountDown");
  16. this.bg = this.node.getChildByPath("GameRoot/Bg");
  17. const path: string = "Res/Theme/Theme1/BG0/BG1-hd.pvr.ccz"
  18. resources.load(path, SpriteFrame, (error: Error, frame: SpriteFrame)=>{
  19. if(error){
  20. console.error("No found!")
  21. //console.log(frame)
  22. } else{
  23. this.bg.getComponent(Sprite).spriteFrame = frame;
  24. }
  25. })
  26. }
  27. update(deltaTime: number) {
  28. //倒计时结束,游戏开始
  29. if(this.countDownTS.isOver){
  30. }
  31. }
  32. }