fill.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { _decorator, Component, Node, Sprite, SpriteFrame } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('fill')
  4. export class fill extends Component {
  5. public isStart:boolean =false;
  6. public curTimme:number =0;
  7. public allTime:number =0;
  8. @property(SpriteFrame) sf_hong:SpriteFrame =null;
  9. @property(SpriteFrame) sf_lv:SpriteFrame =null;
  10. @property(SpriteFrame) sf_huang:SpriteFrame =null;
  11. start() {
  12. }
  13. update(deltaTime: number) {
  14. if(this.isStart){
  15. let d = (this.allTime-this.curTimme)/this.allTime
  16. this.node.getComponent(Sprite).fillRange = 1-d
  17. this.curTimme-=deltaTime
  18. if(this.sf_hong!=null){
  19. if(this.curTimme<=10){
  20. this.node.getComponent(Sprite).spriteFrame = this.sf_hong;
  21. }else if(this.curTimme>10&&this.curTimme<=20){
  22. this.node.getComponent(Sprite).spriteFrame = this.sf_huang;
  23. }else{
  24. this.node.getComponent(Sprite).spriteFrame = this.sf_lv;
  25. }
  26. }
  27. }
  28. }
  29. startAni(_cur:number,_all:number){
  30. if(this.curTimme!=_cur){
  31. this.curTimme = _cur;
  32. }
  33. if(this.allTime!=_all){
  34. this.allTime = _all;
  35. }
  36. if(this.isStart==true){
  37. }else{
  38. this.isStart = true;
  39. }
  40. }
  41. stopAni(){
  42. this.node.getComponent(Sprite).fillRange = 0;
  43. this.isStart = false;
  44. }
  45. }