import { _decorator, Component, Node, Sprite, SpriteFrame } from 'cc'; const { ccclass, property } = _decorator; @ccclass('fill') export class fill extends Component { public isStart:boolean =false; public curTimme:number =0; public allTime:number =0; @property(SpriteFrame) sf_hong:SpriteFrame =null; @property(SpriteFrame) sf_lv:SpriteFrame =null; @property(SpriteFrame) sf_huang:SpriteFrame =null; start() { } update(deltaTime: number) { if(this.isStart){ let d = (this.allTime-this.curTimme)/this.allTime this.node.getComponent(Sprite).fillRange = 1-d this.curTimme-=deltaTime if(this.sf_hong!=null){ if(this.curTimme<=10){ this.node.getComponent(Sprite).spriteFrame = this.sf_hong; }else if(this.curTimme>10&&this.curTimme<=20){ this.node.getComponent(Sprite).spriteFrame = this.sf_huang; }else{ this.node.getComponent(Sprite).spriteFrame = this.sf_lv; } } } } startAni(_cur:number,_all:number){ if(this.curTimme!=_cur){ this.curTimme = _cur; } if(this.allTime!=_all){ this.allTime = _all; } if(this.isStart==true){ }else{ this.isStart = true; } } stopAni(){ this.node.getComponent(Sprite).fillRange = 0; this.isStart = false; } }