新增time.totalTime
This commit is contained in:
@@ -139,10 +139,6 @@ es.Core.scene = new MainScene();
|
|||||||
|
|
||||||
### 示例地址
|
### 示例地址
|
||||||
|
|
||||||
- [egret]: https://github.com/esengine/ecs-egret-demo "egret"
|
|
||||||
|
|
||||||
- [laya]: https://github.com/esengine/ecs-laya-demo "laya"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## 版本计划功能
|
## 版本计划功能
|
||||||
|
|||||||
3
source/bin/framework.d.ts
vendored
3
source/bin/framework.d.ts
vendored
@@ -638,11 +638,12 @@ declare class StringUtils {
|
|||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class Time {
|
class Time {
|
||||||
|
static totalTime: number;
|
||||||
static unscaledDeltaTime: any;
|
static unscaledDeltaTime: any;
|
||||||
static deltaTime: number;
|
static deltaTime: number;
|
||||||
static timeScale: number;
|
static timeScale: number;
|
||||||
static frameCount: number;
|
static frameCount: number;
|
||||||
static _timeSinceSceneLoad: any;
|
static timeSinceSceneLoad: any;
|
||||||
private static _lastTime;
|
private static _lastTime;
|
||||||
static update(currentTime: number): void;
|
static update(currentTime: number): void;
|
||||||
static sceneChanged(): void;
|
static sceneChanged(): void;
|
||||||
|
|||||||
@@ -3136,17 +3136,18 @@ var es;
|
|||||||
}
|
}
|
||||||
Time.update = function (currentTime) {
|
Time.update = function (currentTime) {
|
||||||
var dt = (currentTime - this._lastTime) / 1000;
|
var dt = (currentTime - this._lastTime) / 1000;
|
||||||
|
this.totalTime += dt;
|
||||||
this.deltaTime = dt * this.timeScale;
|
this.deltaTime = dt * this.timeScale;
|
||||||
this.unscaledDeltaTime = dt;
|
this.unscaledDeltaTime = dt;
|
||||||
this._timeSinceSceneLoad += dt;
|
this.timeSinceSceneLoad += dt;
|
||||||
this.frameCount++;
|
this.frameCount++;
|
||||||
this._lastTime = currentTime;
|
this._lastTime = currentTime;
|
||||||
};
|
};
|
||||||
Time.sceneChanged = function () {
|
Time.sceneChanged = function () {
|
||||||
this._timeSinceSceneLoad = 0;
|
this.timeSinceSceneLoad = 0;
|
||||||
};
|
};
|
||||||
Time.checkEvery = function (interval) {
|
Time.checkEvery = function (interval) {
|
||||||
return Math.floor(this._timeSinceSceneLoad / interval) > Math.floor((this._timeSinceSceneLoad - this.deltaTime) / interval);
|
return this.timeSinceSceneLoad / interval > (this.timeSinceSceneLoad - this.deltaTime) / interval;
|
||||||
};
|
};
|
||||||
Time.deltaTime = 0;
|
Time.deltaTime = 0;
|
||||||
Time.timeScale = 1;
|
Time.timeScale = 1;
|
||||||
|
|||||||
2
source/bin/framework.min.js
vendored
2
source/bin/framework.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1,6 +1,8 @@
|
|||||||
module es {
|
module es {
|
||||||
/** 提供帧定时信息 */
|
/** 提供帧定时信息 */
|
||||||
export class Time {
|
export class Time {
|
||||||
|
/** 游戏运行的总时间 */
|
||||||
|
public static totalTime: number;
|
||||||
/** deltaTime的未缩放版本。不受时间尺度的影响 */
|
/** deltaTime的未缩放版本。不受时间尺度的影响 */
|
||||||
public static unscaledDeltaTime;
|
public static unscaledDeltaTime;
|
||||||
/** 前一帧到当前帧的时间增量,按时间刻度进行缩放 */
|
/** 前一帧到当前帧的时间增量,按时间刻度进行缩放 */
|
||||||
@@ -10,21 +12,22 @@ module es {
|
|||||||
/** 已传递的帧总数 */
|
/** 已传递的帧总数 */
|
||||||
public static frameCount = 0;
|
public static frameCount = 0;
|
||||||
/** 自场景加载以来的总时间 */
|
/** 自场景加载以来的总时间 */
|
||||||
public static _timeSinceSceneLoad;
|
public static timeSinceSceneLoad;
|
||||||
private static _lastTime = 0;
|
private static _lastTime = 0;
|
||||||
|
|
||||||
public static update(currentTime: number) {
|
public static update(currentTime: number) {
|
||||||
let dt = (currentTime - this._lastTime) / 1000;
|
let dt = (currentTime - this._lastTime) / 1000;
|
||||||
|
this.totalTime += dt;
|
||||||
this.deltaTime = dt * this.timeScale;
|
this.deltaTime = dt * this.timeScale;
|
||||||
this.unscaledDeltaTime = dt;
|
this.unscaledDeltaTime = dt;
|
||||||
this._timeSinceSceneLoad += dt;
|
this.timeSinceSceneLoad += dt;
|
||||||
this.frameCount++;
|
this.frameCount++;
|
||||||
|
|
||||||
this._lastTime = currentTime;
|
this._lastTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static sceneChanged() {
|
public static sceneChanged() {
|
||||||
this._timeSinceSceneLoad = 0;
|
this.timeSinceSceneLoad = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,7 +36,7 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public static checkEvery(interval: number) {
|
public static checkEvery(interval: number) {
|
||||||
// 我们减去了delta,因为timeSinceSceneLoad已经包含了这个update ticks delta
|
// 我们减去了delta,因为timeSinceSceneLoad已经包含了这个update ticks delta
|
||||||
return Math.floor(this._timeSinceSceneLoad / interval) > Math.floor((this._timeSinceSceneLoad - this.deltaTime) / interval);
|
return this.timeSinceSceneLoad / interval > (this.timeSinceSceneLoad - this.deltaTime) / interval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user