1234567891011121314151617181920212223242526272829303132333435 |
- import { _decorator, Component, Node, Sprite } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('buff_time_count')
- export class buff_time_count extends Component {
- @property(Node) buff_time_bar:Node =null
- private mCallBack = null
- private time_count:number = 0
- private total:number = 0
- public startBuffTimeCount(call_back,time:number){
- this.total = time
- this.time_count = 0
- this.mCallBack = call_back
- this.buff_time_bar.getComponent(Sprite).fillRange = 1
- }
- protected update(dt: number): void {
- if(this.mCallBack!=null){
- this.time_count+=dt
- this.buff_time_bar.getComponent(Sprite).fillRange = 1-this.time_count/this.total
- if(this.time_count>=this.total){
- this.mCallBack()
- this.mCallBack = null
- }
- }
- }
- public cancelTimeCount(){
- this.mCallBack = 0
- this.time_count = 0
- this.buff_time_bar.getComponent(Sprite).fillRange = 1
- }
- }
|