sceneChanged事件
This commit is contained in:
5
demo/libs/framework/framework.d.ts
vendored
5
demo/libs/framework/framework.d.ts
vendored
@@ -661,7 +661,10 @@ declare class Time {
|
||||
static timeScale: number;
|
||||
static frameCount: number;
|
||||
private static _lastTime;
|
||||
static _timeSinceSceneLoad: any;
|
||||
static update(currentTime: number): void;
|
||||
static sceneChanged(): void;
|
||||
static checkEvery(interval: number): boolean;
|
||||
}
|
||||
declare class GraphicsCapabilities {
|
||||
supportsTextureFilterAnisotropic: boolean;
|
||||
@@ -1043,7 +1046,7 @@ declare class Emitter<T> {
|
||||
constructor();
|
||||
addObserver(eventType: T, handler: Function): void;
|
||||
removeObserver(eventType: T, handler: Function): void;
|
||||
emit(eventType: T, data: any): void;
|
||||
emit(eventType: T, data?: any): void;
|
||||
}
|
||||
declare class GlobalManager {
|
||||
static globalManagers: GlobalManager[];
|
||||
|
||||
@@ -1489,6 +1489,8 @@ var SceneManager = (function () {
|
||||
this.activeSceneChanged(current, next);
|
||||
};
|
||||
SceneManager.prototype.onSceneChanged = function () {
|
||||
SceneManager.emitter.emit(CoreEvents.SceneChanged);
|
||||
Time.sceneChanged();
|
||||
};
|
||||
return SceneManager;
|
||||
}());
|
||||
@@ -3036,14 +3038,20 @@ var RenderableComponentList = (function () {
|
||||
var Time = (function () {
|
||||
function Time() {
|
||||
}
|
||||
;
|
||||
Time.update = function (currentTime) {
|
||||
var dt = (currentTime - this._lastTime) / 1000;
|
||||
this.deltaTime = dt * this.timeScale;
|
||||
this.unscaledDeltaTime = dt;
|
||||
this._timeSinceSceneLoad += dt;
|
||||
this.frameCount++;
|
||||
this._lastTime = currentTime;
|
||||
};
|
||||
Time.sceneChanged = function () {
|
||||
this._timeSinceSceneLoad = 0;
|
||||
};
|
||||
Time.checkEvery = function (interval) {
|
||||
return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval);
|
||||
};
|
||||
Time.deltaTime = 0;
|
||||
Time.timeScale = 1;
|
||||
Time.frameCount = 0;
|
||||
|
||||
2
demo/libs/framework/framework.min.js
vendored
2
demo/libs/framework/framework.min.js
vendored
File diff suppressed because one or more lines are too long
5
source/bin/framework.d.ts
vendored
5
source/bin/framework.d.ts
vendored
@@ -661,7 +661,10 @@ declare class Time {
|
||||
static timeScale: number;
|
||||
static frameCount: number;
|
||||
private static _lastTime;
|
||||
static _timeSinceSceneLoad: any;
|
||||
static update(currentTime: number): void;
|
||||
static sceneChanged(): void;
|
||||
static checkEvery(interval: number): boolean;
|
||||
}
|
||||
declare class GraphicsCapabilities {
|
||||
supportsTextureFilterAnisotropic: boolean;
|
||||
@@ -1043,7 +1046,7 @@ declare class Emitter<T> {
|
||||
constructor();
|
||||
addObserver(eventType: T, handler: Function): void;
|
||||
removeObserver(eventType: T, handler: Function): void;
|
||||
emit(eventType: T, data: any): void;
|
||||
emit(eventType: T, data?: any): void;
|
||||
}
|
||||
declare class GlobalManager {
|
||||
static globalManagers: GlobalManager[];
|
||||
|
||||
@@ -1489,6 +1489,8 @@ var SceneManager = (function () {
|
||||
this.activeSceneChanged(current, next);
|
||||
};
|
||||
SceneManager.prototype.onSceneChanged = function () {
|
||||
SceneManager.emitter.emit(CoreEvents.SceneChanged);
|
||||
Time.sceneChanged();
|
||||
};
|
||||
return SceneManager;
|
||||
}());
|
||||
@@ -3036,14 +3038,20 @@ var RenderableComponentList = (function () {
|
||||
var Time = (function () {
|
||||
function Time() {
|
||||
}
|
||||
;
|
||||
Time.update = function (currentTime) {
|
||||
var dt = (currentTime - this._lastTime) / 1000;
|
||||
this.deltaTime = dt * this.timeScale;
|
||||
this.unscaledDeltaTime = dt;
|
||||
this._timeSinceSceneLoad += dt;
|
||||
this.frameCount++;
|
||||
this._lastTime = currentTime;
|
||||
};
|
||||
Time.sceneChanged = function () {
|
||||
this._timeSinceSceneLoad = 0;
|
||||
};
|
||||
Time.checkEvery = function (interval) {
|
||||
return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval);
|
||||
};
|
||||
Time.deltaTime = 0;
|
||||
Time.timeScale = 1;
|
||||
Time.frameCount = 0;
|
||||
|
||||
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
@@ -125,6 +125,7 @@ class SceneManager {
|
||||
* 在一个场景结束后,下一个场景开始之前调用
|
||||
*/
|
||||
public onSceneChanged(){
|
||||
|
||||
SceneManager.emitter.emit(CoreEvents.SceneChanged);
|
||||
Time.sceneChanged();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,38 @@
|
||||
/** 提供帧定时信息 */
|
||||
class Time {
|
||||
/** deltaTime的未缩放版本。不受时间尺度的影响 */
|
||||
public static unscaledDeltaTime;
|
||||
/** 前一帧到当前帧的时间增量,按时间刻度进行缩放 */
|
||||
public static deltaTime: number = 0;
|
||||
/** 时间刻度缩放 */
|
||||
public static timeScale = 1;
|
||||
public static frameCount = 0;;
|
||||
/** 已传递的帧总数 */
|
||||
public static frameCount = 0;
|
||||
|
||||
private static _lastTime = 0;
|
||||
/** 自场景加载以来的总时间 */
|
||||
public static _timeSinceSceneLoad;
|
||||
|
||||
public static update(currentTime: number){
|
||||
let dt = (currentTime - this._lastTime) / 1000;
|
||||
this.deltaTime = dt * this.timeScale;
|
||||
this.unscaledDeltaTime = dt;
|
||||
this._timeSinceSceneLoad += dt;
|
||||
this.frameCount ++;
|
||||
|
||||
this._lastTime = currentTime;
|
||||
}
|
||||
|
||||
public static sceneChanged(){
|
||||
this._timeSinceSceneLoad = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 允许在间隔检查。只应该使用高于delta的间隔值,否则它将始终返回true。
|
||||
* @param interval
|
||||
*/
|
||||
public static checkEvery(interval: number){
|
||||
// 我们减去了delta,因为timeSinceSceneLoad已经包含了这个update ticks delta
|
||||
return (this._timeSinceSceneLoad / interval) > ((this._timeSinceSceneLoad - this.deltaTime) / interval);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ class Emitter<T> {
|
||||
this._messageTable.get(eventType).remove(handler);
|
||||
}
|
||||
|
||||
public emit(eventType: T, data: any){
|
||||
public emit(eventType: T, data?: any){
|
||||
let list: Function[] = this._messageTable.get(eventType);
|
||||
if (list){
|
||||
for (let i = list.length - 1; i >= 0; i --)
|
||||
|
||||
Reference in New Issue
Block a user