Files
esengine/source/src/ECS/Systems/IntervalSystem.ts

40 lines
1.0 KiB
TypeScript
Raw Normal View History

module es {
/**
*
*/
export abstract class IntervalSystem extends EntitySystem {
/**
*
*/
protected acc: number = 0;
/**
*
*/
private readonly interval: number = 0;
private intervalDelta: number = 0;
constructor(matcher: Matcher, interval: number) {
super(matcher);
this.interval = interval;
}
protected checkProcessing() {
this.acc += Time.deltaTime;
if (this.acc >= this.interval) {
this.acc -= this.interval;
this.intervalDelta = (this.acc - this.intervalDelta);
return true;
}
return false;
}
/**
* delta值
*/
protected getIntervalDelta() {
return this.interval + this.intervalDelta;
}
}
}