// 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 { //圖片編號 num = 1; //圖片陣列 @property(cc.SpriteFrame) sprfrms:cc.SpriteFrame[] = []; onLoad () { //觸控 this.node.on("touchstart", this.show1, this); //啟動計時器 this.schedule(this.timer, 0.2); } //觸控事件 show1(e:cc.Event.EventTouch) { //抓取節點『提示框節點』 var node1 = cc.find("Canvas/提示框節點"); node1.active = true; // e.stopPropagation(); } //計時器動畫 timer() { //圖片編號+1 this.num += 1; if(this.num >=3)this.num = 1; //抓到圖片節點的組件 var comp1 = cc.find("Canvas/貓").getComponent(cc.Sprite); comp1.spriteFrame = this.sprfrms[this.num-1]; } start () { } // update (dt) {} }