// 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) altas1:cc.SpriteAtlas = null; //圖片陣列 @property(cc.SpriteFrame) sprfrms:cc.SpriteFrame[] = []; //圖片編號 num = 0; onLoad () { //啟動計時器 this.schedule(this.timer, 0.2); //抓取節點的sprite組件 var sprcomp1 = this.getComponent(cc.Sprite); //把圖集altas轉成,圖片陣列 this.sprfrms = this.altas1.getSpriteFrames(); } timer() { //抓取節點的sprite組件 var comp1 = this.getComponent(cc.Sprite); //設定sprite組件的圖片source comp1.spriteFrame = this.sprfrms[this.num]; //圖片編號+1 this.num += 1; if(this.num >= 17)this.num =0; } start () { } // update (dt) {} }