// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html const {ccclass, property} = cc._decorator; @ccclass export default class NewClass extends cc.Component { // @property(cc.Label) // label: cc.Label = null; // @property // text: string = 'hello'; //圖集spriteAtlas @property(cc.SpriteAtlas) a3 = null; //圖片陣列 @property(cc.SpriteFrame) img = []; //圖片編號 num = 1; onLoad () { //啟動計時器 this.schedule(this.timer, 0.1); //把圖集altas轉成,圖片陣列 this.img = this.a3.getSpriteFrames(); } timer() { //圖片編號+1 this.num += 1; if(this.num == 18)this.num =1; //設定sprite組件的圖片source this.node.getComponent(cc.Sprite).spriteFrame = this.img[this.num-1]; } start () { } // update (dt) {} }