修复运行时未初始化

This commit is contained in:
yhh
2020-07-23 19:28:01 +08:00
parent 79c5d6990c
commit d4c244daf5
18 changed files with 283 additions and 303 deletions
+3 -3
View File
@@ -248,7 +248,6 @@ declare module es {
}
declare module es {
class Core extends egret.DisplayObjectContainer {
static activeSceneChanged: Function;
static emitter: Emitter<CoreEvents>;
static graphicsDevice: GraphicsDevice;
static content: ContentManager;
@@ -260,6 +259,7 @@ declare module es {
_globalManagers: GlobalManager[];
static scene: Scene;
constructor();
private onAddToStage;
onOrientationChanged(): void;
protected onGraphicsDeviceReset(): void;
protected initialize(): void;
@@ -269,7 +269,6 @@ declare module es {
endDebugUpdate(): void;
onSceneChanged(): void;
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
static registerActiveSceneChanged(current: Scene, next: Scene): void;
static registerGlobalManager(manager: es.GlobalManager): void;
static unregisterGlobalManager(manager: es.GlobalManager): void;
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
@@ -1679,7 +1678,8 @@ declare module es {
static readonly logSnapDuration: number;
static readonly barPadding: number;
static readonly autoAdjustDelay: number;
static Instance: TimeRuler;
private static _instance;
static readonly Instance: TimeRuler;
private _frameKey;
private _logKey;
private _logs;
+22 -12
View File
@@ -1105,13 +1105,8 @@ var es;
_this._globalManagers = [];
Core._instance = _this;
Core.emitter = new es.Emitter();
Core.graphicsDevice = new es.GraphicsDevice();
Core.content = new es.ContentManager();
_this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.initialize, _this);
_this.addEventListener(egret.Event.RESIZE, _this.onGraphicsDeviceReset, _this);
_this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, _this.onOrientationChanged, _this);
_this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this);
_this.addEventListener(egret.Event.RENDER, _this.draw, _this);
_this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
return _this;
}
Object.defineProperty(Core, "Instance", {
@@ -1123,6 +1118,8 @@ var es;
});
Object.defineProperty(Core, "scene", {
get: function () {
if (!this._instance)
return null;
return this._instance._scene;
},
set: function (value) {
@@ -1138,11 +1135,18 @@ var es;
else {
this._instance._nextScene = value;
}
this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene);
},
enumerable: true,
configurable: true
});
Core.prototype.onAddToStage = function () {
Core.graphicsDevice = new es.GraphicsDevice();
this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this);
this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this);
this.addEventListener(egret.Event.ENTER_FRAME, this.update, this);
this.addEventListener(egret.Event.RENDER, this.draw, this);
this.initialize();
};
Core.prototype.onOrientationChanged = function () {
Core.emitter.emit(es.CoreEvents.OrientationChanged);
};
@@ -1228,10 +1232,6 @@ var es;
this._instance._sceneTransition = sceneTransition;
return sceneTransition;
};
Core.registerActiveSceneChanged = function (current, next) {
if (this.activeSceneChanged)
this.activeSceneChanged(current, next);
};
Core.registerGlobalManager = function (manager) {
this._instance._globalManagers.push(manager);
manager.enabled = true;
@@ -4308,6 +4308,8 @@ var es;
this.platformInitialize(device);
};
GraphicsCapabilities.prototype.platformInitialize = function (device) {
if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
return;
var capabilities = this;
capabilities["isMobile"] = true;
var systemInfo = wx.getSystemInfoSync();
@@ -7570,7 +7572,6 @@ var es;
this.stopwacth = new stopwatch.Stopwatch();
this._markerNameToIdMap = new Map();
this.showLog = false;
TimeRuler.Instance = this;
this._logs = new Array(2);
for (var i = 0; i < this._logs.length; ++i)
this._logs[i] = new FrameLog();
@@ -7579,6 +7580,15 @@ var es;
es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this);
this.onGraphicsDeviceReset();
}
Object.defineProperty(TimeRuler, "Instance", {
get: function () {
if (!this._instance)
this._instance = new TimeRuler();
return this._instance;
},
enumerable: true,
configurable: true
});
TimeRuler.prototype.onGraphicsDeviceReset = function () {
var layout = new es.Layout();
this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location;
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -2
View File
@@ -11,12 +11,11 @@
"libs/long/long.js"
],
"game": [
"bin-debug/game/CoreEmitterType.js",
"bin-debug/AssetAdapter.js",
"bin-debug/LoadingUI.js",
"bin-debug/Main.js",
"bin-debug/Platform.js",
"bin-debug/ThemeAdapter.js",
"bin-debug/LoadingUI.js",
"bin-debug/game/MainScene.js",
"bin-debug/game/PlayerController.js",
"bin-debug/game/SimplePooled.js",
+5 -55
View File
@@ -27,43 +27,9 @@
//
//////////////////////////////////////////////////////////////////////////////////////
import SceneManager = es.SceneManager;
import Emitter = es.Emitter;
class Main extends SceneManager {
public static emitter: Emitter<CoreEmitterType>;
public static manager: SceneManager;
protected createChildren(): void {
super.createChildren();
egret.lifecycle.addLifecycleListener((context) => {
// custom lifecycle plugin
})
egret.lifecycle.onPause = () => {
egret.ticker.pause();
}
egret.lifecycle.onResume = () => {
egret.ticker.resume();
}
//inject the custom material parser
//注入自定义的素材解析器
let assetAdapter = new AssetAdapter();
egret.registerImplementation("eui.IAssetAdapter", assetAdapter);
egret.registerImplementation("eui.IThemeAdapter", new ThemeAdapter());
Main.manager = new SceneManager(this.stage);
Main.emitter = new Emitter<CoreEmitterType>();
this.addEventListener(egret.Event.ENTER_FRAME, this.updateFrame, this);
this.runGame();
}
private updateFrame(evt: egret.Event){
Main.emitter.emit(CoreEmitterType.Update, evt);
class Main extends es.Core {
protected async initialize() {
await this.runGame();
}
private async runGame() {
@@ -71,12 +37,12 @@ class Main extends SceneManager {
this.createGameScene();
}
private async loadResource() {
try {
const loadingView = new LoadingUI();
this.stage.addChild(loadingView);
await RES.loadConfig("resource/default.res.json", "resource/");
await this.loadTheme();
await RES.loadGroup("preload", 0, loadingView);
this.stage.removeChild(loadingView);
}
@@ -85,27 +51,11 @@ class Main extends SceneManager {
}
}
private loadTheme() {
return new Promise((resolve, reject) => {
// load skin theme configuration file, you can manually modify the file. And replace the default skin.
//加载皮肤主题配置文件,可以手动修改这个文件。替换默认皮肤。
let theme = new eui.Theme("resource/default.thm.json", this.stage);
theme.addEventListener(eui.UIEvent.COMPLETE, () => {
resolve();
}, this);
})
}
/**
*
* Create scene interface
*/
protected createGameScene(): void {
SceneManager.scene = new MainScene();
// Main.emitter.addObserver(CoreEmitterType.Update, ()=>{
// console.log("update emitter");
// });
es.Core.scene = new scene.MainScene();
}
}
-3
View File
@@ -1,3 +0,0 @@
enum CoreEmitterType {
Update,
}
+82 -87
View File
@@ -1,95 +1,90 @@
class MainScene extends Scene {
constructor() {
super();
module scene {
export class MainScene extends es.Scene {
constructor() {
super();
// this.addEntityProcessor(new SpawnerSystem(new Matcher()));
this.astarTest();
this.dijkstraTest();
this.breadthfirstTest();
}
public async onStart() {
let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
let bg = this.createEntity("bg");
bg.addComponent(new SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
bg.addComponent(new PlayerController());
bg.addComponent(new Mover());
bg.addComponent(new ScrollingSpriteRenderer(sprite));
bg.addComponent(new BoxCollider());
bg.position = new Vector2(Math.random() * 200, Math.random() * 200);
for (let i = 0; i < 1; i++) {
let sprite = new Sprite(RES.getRes("checkbox_select_disabled_png"));
let player2 = this.createEntity("player2");
player2.addComponent(new SpriteRenderer()).setSprite(sprite);
player2.position = new Vector2(Math.random() * 100, Math.random() * 100);
player2.addComponent(new BoxCollider());
// this.addEntityProcessor(new SpawnerSystem(new Matcher()));
this.astarTest();
this.dijkstraTest();
this.breadthfirstTest();
}
this.camera.follow(bg, CameraStyle.lockOn);
public async onStart() {
let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
let bg = this.createEntity("bg");
bg.addComponent(new es.SpriteRenderer()).setSprite(sprite).setColor(0xff0000);
bg.addComponent(new component.PlayerController());
bg.addComponent(new es.Mover());
bg.addComponent(new es.ScrollingSpriteRenderer(sprite));
bg.addComponent(new es.BoxCollider());
bg.position = new es.Vector2(Math.random() * 200, Math.random() * 200);
let pool = new ComponentPool<SimplePooled>(SimplePooled);
let c1 = pool.obtain();
let c2 = pool.obtain();
pool.free(c1);
let c1b = pool.obtain();
for (let i = 0; i < 1; i++) {
let sprite = new es.Sprite(RES.getRes("checkbox_select_disabled_png"));
let player2 = this.createEntity("player2");
player2.addComponent(new es.SpriteRenderer()).setSprite(sprite);
player2.position = new es.Vector2(Math.random() * 100, Math.random() * 100);
player2.addComponent(new es.BoxCollider());
}
console.log(c1 != c2);
console.log(c1 == c1b);
this.camera.follow(bg, es.CameraStyle.lockOn);
let button = new eui.Button();
button.label = "切换场景";
this.addChild(button);
button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
SceneManager.startSceneTransition(new FadeTransition(() => {
return new MainScene();
}));
}, this);
let pool = new es.ComponentPool<component.SimplePooled>(component.SimplePooled);
let c1 = pool.obtain();
let c2 = pool.obtain();
pool.free(c1);
let c1b = pool.obtain();
Main.emitter.addObserver(CoreEmitterType.Update, this.handleFuncTest, this);
console.log(c1 != c2);
console.log(c1 == c1b);
let button = new eui.Button();
button.label = "切换场景";
this.addChild(button);
button.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
es.Core.startSceneTransition(new es.FadeTransition(() => {
return new MainScene();
}));
}, this);
}
public breadthfirstTest() {
let graph = new es.UnweightedGraph<string>();
graph.addEdgesForNode("a", ["b"]); // a->b
graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d
graph.addEdgesForNode("c", ["a"]); // c->a
graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a
graph.addEdgesForNode("e", ["b"]); // e->b
// 计算从c到e的路径
let path = es.BreadthFirstPathfinder.search(graph, "c", "e");
console.log(path);
}
public dijkstraTest() {
let graph = new es.WeightedGridGraph(20, 20);
graph.weightedNodes.push(new es.Vector2(3, 3));
graph.weightedNodes.push(new es.Vector2(3, 4));
graph.weightedNodes.push(new es.Vector2(4, 3));
graph.weightedNodes.push(new es.Vector2(4, 4));
let path = graph.search(new es.Vector2(3, 4), new es.Vector2(15, 17));
console.log(path);
}
public astarTest() {
let graph = new es.AstarGridGraph(30, 30);
// graph.weightedNodes.push(new Vector2(3, 3));
// graph.weightedNodes.push(new Vector2(3, 4));
// graph.weightedNodes.push(new Vector2(4, 3));
// graph.weightedNodes.push(new Vector2(4, 4));
let startTime = egret.getTimer();
let path = graph.search(new es.Vector2(1, 1), new es.Vector2(29, 29));
console.log(egret.getTimer() - startTime);
}
}
/** 测试Emitter */
private handleFuncTest(){
Main.emitter.removeObserver(CoreEmitterType.Update, this.handleFuncTest);
}
public breadthfirstTest() {
let graph = new UnweightedGraph<string>();
graph.addEdgesForNode("a", ["b"]); // a->b
graph.addEdgesForNode("b", ["a", "c", "d"]); // b->a b->c b->d
graph.addEdgesForNode("c", ["a"]); // c->a
graph.addEdgesForNode("d", ["e", "a"]); // d->e d->a
graph.addEdgesForNode("e", ["b"]); // e->b
// 计算从c到e的路径
let path = BreadthFirstPathfinder.search(graph, "c", "e");
console.log(path);
}
public dijkstraTest() {
let graph = new WeightedGridGraph(20, 20);
graph.weightedNodes.push(new Vector2(3, 3));
graph.weightedNodes.push(new Vector2(3, 4));
graph.weightedNodes.push(new Vector2(4, 3));
graph.weightedNodes.push(new Vector2(4, 4));
let path = graph.search(new Vector2(3, 4), new Vector2(15, 17));
console.log(path);
}
public astarTest() {
let graph = new AstarGridGraph(30, 30);
// graph.weightedNodes.push(new Vector2(3, 3));
// graph.weightedNodes.push(new Vector2(3, 4));
// graph.weightedNodes.push(new Vector2(4, 3));
// graph.weightedNodes.push(new Vector2(4, 4));
let startTime = egret.getTimer();
let path = graph.search(new Vector2(1, 1), new Vector2(29, 29));
console.log(egret.getTimer() - startTime);
}
}
}
+53 -45
View File
@@ -1,56 +1,64 @@
class PlayerController extends Component {
private down: boolean = false;
private touchPoint: Vector2 = Vector2.zero;
private mover: Mover;
private spriteRenderer: SpriteRenderer;
module component {
import Component = es.Component;
import Vector2 = es.Vector2;
import Mover = es.Mover;
import SpriteRenderer = es.SpriteRenderer;
import Time = es.Time;
import Input = es.Input;
public onAddedToEntity(){
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this);
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
}
export class PlayerController extends Component {
private down: boolean = false;
private touchPoint: Vector2 = Vector2.zero;
private mover: Mover;
private spriteRenderer: SpriteRenderer;
private touchBegin(evt: egret.TouchEvent){
this.down = true;
this.touchPoint = new Vector2(evt.stageX, evt.stageY);
}
public onAddedToEntity(){
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchBegin, this);
this.entity.scene.stage.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
}
private touchEnd(evt: egret.TouchEvent){
this.down = false;
this.touchPoint = new Vector2(evt.stageX, evt.stageY);
}
private touchBegin(evt: egret.TouchEvent){
this.down = true;
this.touchPoint = new Vector2(evt.stageX, evt.stageY);
}
public update(){
if (!this.mover)
this.mover = this.entity.getComponent<Mover>(Mover);
private touchEnd(evt: egret.TouchEvent){
this.down = false;
this.touchPoint = new Vector2(evt.stageX, evt.stageY);
}
if (!this.spriteRenderer)
this.spriteRenderer = this.entity.getComponent<SpriteRenderer>(SpriteRenderer);
public update(){
if (!this.mover)
this.mover = this.entity.getComponent<Mover>(Mover);
if (!this.mover)
return;
if (!this.spriteRenderer)
this.spriteRenderer = this.entity.getComponent<SpriteRenderer>(SpriteRenderer);
if (!SpriteRenderer)
return;
if (!this.mover)
return;
if (this.down){
let camera = SceneManager.scene.camera;
let moveLeft: number = 0;
let moveRight: number = 0;
let speed = 100;
let worldPos = Input.touchPosition;
if (worldPos.x < this.spriteRenderer.localPosition.x){
moveLeft = -1;
} else if(worldPos.x > this.spriteRenderer.localPosition.x){
moveLeft = 1;
if (!SpriteRenderer)
return;
if (this.down){
let moveLeft: number = 0;
let moveRight: number = 0;
let speed = 100;
let worldPos = Input.touchPosition;
if (worldPos.x < this.spriteRenderer.transform.position.x){
moveLeft = -1;
} else if(worldPos.x > this.spriteRenderer.transform.position.x){
moveLeft = 1;
}
if (worldPos.y < this.spriteRenderer.transform.position.y){
moveRight = -1;
} else if(worldPos.y > this.spriteRenderer.transform.position.y){
moveRight = 1;
}
this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
}
if (worldPos.y < this.spriteRenderer.localPosition.y){
moveRight = -1;
} else if(worldPos.y > this.spriteRenderer.localPosition.y){
moveRight = 1;
}
this.mover.move(new Vector2(moveLeft * speed * Time.deltaTime, moveRight * speed * Time.deltaTime));
}
}
}
}
+8 -4
View File
@@ -1,5 +1,9 @@
class SimplePooled extends PooledComponent {
public reset(){
module component {
import PooledComponent = es.PooledComponent;
export class SimplePooled extends PooledComponent {
public reset(){
}
}
}
}
+32 -30
View File
@@ -1,35 +1,37 @@
class SpawnComponent extends Component implements ITriggerListener {
public cooldown = -1;
public minInterval = 2;
public maxInterval = 60;
public enemyType = EnemyType.worm;
public numSpawned = 0;
public numAlive = 0;
module component {
export class SpawnComponent extends es.Component implements es.ITriggerListener {
public cooldown = -1;
public minInterval = 2;
public maxInterval = 60;
public enemyType = EnemyType.worm;
public numSpawned = 0;
public numAlive = 0;
constructor(enemyType: EnemyType) {
super();
this.enemyType = enemyType;
constructor(enemyType: EnemyType) {
super();
this.enemyType = enemyType;
}
public initialize() {
// console.log("initialize");
}
public update() {
// console.log("update");
}
public onTriggerEnter(other: es.Collider, local: es.Collider){
if (other == local)
console.log("repeat collider");
console.log("enter collider");
}
public onTriggerExit(other: es.Collider, local: es.Collider){
console.log("exit collider");
}
}
public initialize() {
// console.log("initialize");
}
public update() {
// console.log("update");
}
public onTriggerEnter(other: Collider, local: Collider){
if (other == local)
console.log("repeat collider")
console.log("enter collider");
}
public onTriggerExit(other: Collider, local: Collider){
console.log("exit collider");
export enum EnemyType {
worm
}
}
enum EnemyType {
worm
}
+31 -29
View File
@@ -1,34 +1,36 @@
class SpawnerSystem extends EntityProcessingSystem {
constructor(matcher: Matcher){
super(matcher);
}
public processEntity(entity: Entity){
let spawner = entity.getComponent<SpawnComponent>(SpawnComponent);
if (!spawner)
return;
if (spawner.numAlive <= 0)
spawner.enabled = true;
if (!spawner.enabled)
return;
console.log("cooldown", spawner.cooldown);
if (spawner.cooldown == -1){
spawner.cooldown = Math.random() * 60;
spawner.cooldown /= 4;
module system {
export class SpawnerSystem extends es.EntityProcessingSystem {
constructor(matcher: es.Matcher){
super(matcher);
}
spawner.cooldown -= Time.deltaTime;
if (spawner.cooldown <= 0){
spawner.cooldown = Math.random() * 60;
// CreateEnemy
spawner.numSpawned ++;
spawner.numAlive ++;
public processEntity(entity: es.Entity){
let spawner = entity.getComponent<component.SpawnComponent>(component.SpawnComponent);
if (!spawner)
return;
if (spawner.numAlive > 0)
spawner.enabled = false;
if (spawner.numAlive <= 0)
spawner.enabled = true;
if (!spawner.enabled)
return;
console.log("cooldown", spawner.cooldown);
if (spawner.cooldown == -1){
spawner.cooldown = Math.random() * 60;
spawner.cooldown /= 4;
}
spawner.cooldown -= es.Time.deltaTime;
if (spawner.cooldown <= 0){
spawner.cooldown = Math.random() * 60;
// CreateEnemy
spawner.numSpawned ++;
spawner.numAlive ++;
if (spawner.numAlive > 0)
spawner.enabled = false;
}
}
}
}
}
+3 -3
View File
@@ -248,7 +248,6 @@ declare module es {
}
declare module es {
class Core extends egret.DisplayObjectContainer {
static activeSceneChanged: Function;
static emitter: Emitter<CoreEvents>;
static graphicsDevice: GraphicsDevice;
static content: ContentManager;
@@ -260,6 +259,7 @@ declare module es {
_globalManagers: GlobalManager[];
static scene: Scene;
constructor();
private onAddToStage;
onOrientationChanged(): void;
protected onGraphicsDeviceReset(): void;
protected initialize(): void;
@@ -269,7 +269,6 @@ declare module es {
endDebugUpdate(): void;
onSceneChanged(): void;
static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T;
static registerActiveSceneChanged(current: Scene, next: Scene): void;
static registerGlobalManager(manager: es.GlobalManager): void;
static unregisterGlobalManager(manager: es.GlobalManager): void;
static getGlobalManager<T extends es.GlobalManager>(type: any): T;
@@ -1679,7 +1678,8 @@ declare module es {
static readonly logSnapDuration: number;
static readonly barPadding: number;
static readonly autoAdjustDelay: number;
static Instance: TimeRuler;
private static _instance;
static readonly Instance: TimeRuler;
private _frameKey;
private _logKey;
private _logs;
+22 -12
View File
@@ -1105,13 +1105,8 @@ var es;
_this._globalManagers = [];
Core._instance = _this;
Core.emitter = new es.Emitter();
Core.graphicsDevice = new es.GraphicsDevice();
Core.content = new es.ContentManager();
_this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.initialize, _this);
_this.addEventListener(egret.Event.RESIZE, _this.onGraphicsDeviceReset, _this);
_this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, _this.onOrientationChanged, _this);
_this.addEventListener(egret.Event.ENTER_FRAME, _this.update, _this);
_this.addEventListener(egret.Event.RENDER, _this.draw, _this);
_this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
return _this;
}
Object.defineProperty(Core, "Instance", {
@@ -1123,6 +1118,8 @@ var es;
});
Object.defineProperty(Core, "scene", {
get: function () {
if (!this._instance)
return null;
return this._instance._scene;
},
set: function (value) {
@@ -1138,11 +1135,18 @@ var es;
else {
this._instance._nextScene = value;
}
this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene);
},
enumerable: true,
configurable: true
});
Core.prototype.onAddToStage = function () {
Core.graphicsDevice = new es.GraphicsDevice();
this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this);
this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this);
this.addEventListener(egret.Event.ENTER_FRAME, this.update, this);
this.addEventListener(egret.Event.RENDER, this.draw, this);
this.initialize();
};
Core.prototype.onOrientationChanged = function () {
Core.emitter.emit(es.CoreEvents.OrientationChanged);
};
@@ -1228,10 +1232,6 @@ var es;
this._instance._sceneTransition = sceneTransition;
return sceneTransition;
};
Core.registerActiveSceneChanged = function (current, next) {
if (this.activeSceneChanged)
this.activeSceneChanged(current, next);
};
Core.registerGlobalManager = function (manager) {
this._instance._globalManagers.push(manager);
manager.enabled = true;
@@ -4308,6 +4308,8 @@ var es;
this.platformInitialize(device);
};
GraphicsCapabilities.prototype.platformInitialize = function (device) {
if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
return;
var capabilities = this;
capabilities["isMobile"] = true;
var systemInfo = wx.getSystemInfoSync();
@@ -7570,7 +7572,6 @@ var es;
this.stopwacth = new stopwatch.Stopwatch();
this._markerNameToIdMap = new Map();
this.showLog = false;
TimeRuler.Instance = this;
this._logs = new Array(2);
for (var i = 0; i < this._logs.length; ++i)
this._logs[i] = new FrameLog();
@@ -7579,6 +7580,15 @@ var es;
es.Core.emitter.addObserver(es.CoreEvents.GraphicsDeviceReset, this.onGraphicsDeviceReset, this);
this.onGraphicsDeviceReset();
}
Object.defineProperty(TimeRuler, "Instance", {
get: function () {
if (!this._instance)
this._instance = new TimeRuler();
return this._instance;
},
enumerable: true,
configurable: true
});
TimeRuler.prototype.onGraphicsDeviceReset = function () {
var layout = new es.Layout();
this._position = layout.place(new es.Vector2(this.width, TimeRuler.barHeight), 0, 0.01, es.Alignment.bottomCenter).location;
+1 -1
View File
File diff suppressed because one or more lines are too long
+10 -13
View File
@@ -3,10 +3,6 @@ module es {
*
*/
export class Core extends egret.DisplayObjectContainer {
/**
*
*/
public static activeSceneChanged: Function;
/**
*
*/
@@ -44,6 +40,8 @@ module es {
*
*/
public static get scene() {
if (!this._instance)
return null;
return this._instance._scene;
}
@@ -64,8 +62,6 @@ module es {
} else {
this._instance._nextScene = value;
}
this.registerActiveSceneChanged(this._instance._scene, this._instance._nextScene);
}
constructor() {
@@ -73,14 +69,20 @@ module es {
Core._instance = this;
Core.emitter = new Emitter<CoreEvents>();
Core.graphicsDevice = new GraphicsDevice();
Core.content = new ContentManager();
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.initialize, this);
this.addEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
}
private onAddToStage(){
Core.graphicsDevice = new GraphicsDevice();
this.addEventListener(egret.Event.RESIZE, this.onGraphicsDeviceReset, this);
this.addEventListener(egret.StageOrientationEvent.ORIENTATION_CHANGE, this.onOrientationChanged, this);
this.addEventListener(egret.Event.ENTER_FRAME, this.update, this);
this.addEventListener(egret.Event.RENDER, this.draw, this);
this.initialize();
}
public onOrientationChanged(){
@@ -190,11 +192,6 @@ module es {
return sceneTransition;
}
public static registerActiveSceneChanged(current: Scene, next: Scene){
if (this.activeSceneChanged)
this.activeSceneChanged(current, next);
}
/**
*
* @param manager
@@ -6,6 +6,8 @@ module es {
}
private platformInitialize(device: GraphicsDevice){
if (GraphicsCapabilities.runtimeType != egret.RuntimeType.WXGAME)
return;
let capabilities = this;
capabilities["isMobile"] = true;
+6 -2
View File
@@ -17,7 +17,12 @@ module es {
public static readonly logSnapDuration = 120;
public static readonly barPadding = 2;
public static readonly autoAdjustDelay = 30;
public static Instance: TimeRuler;
private static _instance;
public static get Instance(): TimeRuler{
if (!this._instance)
this._instance = new TimeRuler();
return this._instance;
}
private _frameKey = 'frame';
private _logKey = 'log';
@@ -56,7 +61,6 @@ module es {
private _frameAdjust: number;
constructor() {
TimeRuler.Instance = this;
this._logs = new Array<FrameLog>(2);
for (let i = 0; i < this._logs.length; ++i)
this._logs[i] = new FrameLog();