mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-06-30 07:24:26 +08:00
TimerManager添加stop方法可停止计时
This commit is contained in:
@@ -263,42 +263,35 @@ export class TimerManager extends EventDispatcher {
|
||||
}
|
||||
*/
|
||||
export class Timer {
|
||||
/** 定时到了回调 */
|
||||
callback: Function | null = null;
|
||||
|
||||
private _elapsedTime: number = 0;
|
||||
|
||||
/** 逝去时间 */
|
||||
get elapsedTime(): number {
|
||||
return this._elapsedTime;
|
||||
}
|
||||
|
||||
private _step: number = 0;
|
||||
/** 获取触发间隔时间单位秒 */
|
||||
private _step: number = -1;
|
||||
/** 触发间隔时间(秒) */
|
||||
get step(): number {
|
||||
return this._step;
|
||||
}
|
||||
/** 设置触发间隔时间单位秒 */
|
||||
set step(step: number) {
|
||||
this._step = step; // 每次修改时间
|
||||
this._elapsedTime = 0; // 逝去时间
|
||||
}
|
||||
|
||||
/** 进度 */
|
||||
get progress(): number {
|
||||
return this._elapsedTime / this._step;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
* @param step 每跳动一次步长单位位
|
||||
*/
|
||||
constructor(step: number = 0) {
|
||||
this.step = step;
|
||||
}
|
||||
|
||||
/** 游戏引擎的cc.Component组件的update方法调用 */
|
||||
update(dt: number) {
|
||||
if (this.step <= 0) return false;
|
||||
|
||||
this._elapsedTime += dt;
|
||||
|
||||
if (this._elapsedTime >= this._step) {
|
||||
@@ -309,8 +302,11 @@ export class Timer {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 重置 */
|
||||
reset() {
|
||||
this._elapsedTime = 0;
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.step = -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user