buff_time_count.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { _decorator, Component, Node, Sprite } from 'cc';
  2. const { ccclass, property } = _decorator;
  3. @ccclass('buff_time_count')
  4. export class buff_time_count extends Component {
  5. @property(Node) buff_time_bar:Node =null
  6. private mCallBack = null
  7. private time_count:number = 0
  8. private total:number = 0
  9. public startBuffTimeCount(call_back,time:number){
  10. this.total = time
  11. this.time_count = 0
  12. this.mCallBack = call_back
  13. this.buff_time_bar.getComponent(Sprite).fillRange = 1
  14. }
  15. protected update(dt: number): void {
  16. if(this.mCallBack!=null){
  17. this.time_count+=dt
  18. this.buff_time_bar.getComponent(Sprite).fillRange = 1-this.time_count/this.total
  19. if(this.time_count>=this.total){
  20. this.mCallBack()
  21. this.mCallBack = null
  22. }
  23. }
  24. }
  25. public cancelTimeCount(){
  26. this.mCallBack = 0
  27. this.time_count = 0
  28. this.buff_time_bar.getComponent(Sprite).fillRange = 1
  29. }
  30. }