完善渐隐场景转换
This commit is contained in:
27
demo/libs/framework/framework.d.ts
vendored
27
demo/libs/framework/framework.d.ts
vendored
@@ -167,7 +167,7 @@ declare class Entity {
|
|||||||
readonly components: ComponentList;
|
readonly components: ComponentList;
|
||||||
private _updateOrder;
|
private _updateOrder;
|
||||||
private _enabled;
|
private _enabled;
|
||||||
private _isDestoryed;
|
_isDestoryed: boolean;
|
||||||
private _tag;
|
private _tag;
|
||||||
componentBits: BitSet;
|
componentBits: BitSet;
|
||||||
parent: Transform;
|
parent: Transform;
|
||||||
@@ -234,6 +234,7 @@ declare class Scene extends egret.DisplayObjectContainer {
|
|||||||
protected onStart(): void;
|
protected onStart(): void;
|
||||||
protected onActive(): void;
|
protected onActive(): void;
|
||||||
protected onDeactive(): void;
|
protected onDeactive(): void;
|
||||||
|
protected unload(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
}
|
}
|
||||||
@@ -241,6 +242,7 @@ declare class SceneManager {
|
|||||||
private static _scene;
|
private static _scene;
|
||||||
private static _nextScene;
|
private static _nextScene;
|
||||||
static sceneTransition: SceneTransition;
|
static sceneTransition: SceneTransition;
|
||||||
|
static stage: egret.Stage;
|
||||||
constructor(stage: egret.Stage);
|
constructor(stage: egret.Stage);
|
||||||
static scene: Scene;
|
static scene: Scene;
|
||||||
static initialize(stage: egret.Stage): void;
|
static initialize(stage: egret.Stage): void;
|
||||||
@@ -432,6 +434,7 @@ declare class SpriteRenderer extends RenderableComponent {
|
|||||||
setColor(color: number): void;
|
setColor(color: number): void;
|
||||||
isVisibleFromCamera(camera: Camera): boolean;
|
isVisibleFromCamera(camera: Camera): boolean;
|
||||||
render(camera: Camera): void;
|
render(camera: Camera): void;
|
||||||
|
onRemovedFromEntity(): void;
|
||||||
}
|
}
|
||||||
interface ITriggerListener {
|
interface ITriggerListener {
|
||||||
onTriggerEnter(other: Collider, local: Collider): any;
|
onTriggerEnter(other: Collider, local: Collider): any;
|
||||||
@@ -612,6 +615,7 @@ declare abstract class Renderer {
|
|||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
protected beginRender(cam: Camera): void;
|
protected beginRender(cam: Camera): void;
|
||||||
abstract render(scene: Scene): any;
|
abstract render(scene: Scene): any;
|
||||||
|
unload(): void;
|
||||||
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
|
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
|
||||||
}
|
}
|
||||||
declare class DefaultRenderer extends Renderer {
|
declare class DefaultRenderer extends Renderer {
|
||||||
@@ -628,31 +632,30 @@ declare class ScreenSpaceRenderer extends Renderer {
|
|||||||
render(scene: Scene): void;
|
render(scene: Scene): void;
|
||||||
}
|
}
|
||||||
declare abstract class SceneTransition {
|
declare abstract class SceneTransition {
|
||||||
|
private _hasPreviousSceneRender;
|
||||||
loadsNewScene: boolean;
|
loadsNewScene: boolean;
|
||||||
isNewSceneLoaded: boolean;
|
isNewSceneLoaded: boolean;
|
||||||
wantsPreviousSceneRender: boolean;
|
|
||||||
protected sceneLoadAction: Function;
|
protected sceneLoadAction: Function;
|
||||||
previousSceneRender: egret.RenderTexture;
|
|
||||||
onScreenObscured: Function;
|
onScreenObscured: Function;
|
||||||
onTransitionCompleted: Function;
|
onTransitionCompleted: Function;
|
||||||
progress: number;
|
|
||||||
constructor(sceneLoadAction: Function, wantsPreviousSceneRender?: boolean);
|
|
||||||
private _hasPreviousSceneRender;
|
|
||||||
readonly hasPreviousSceneRender: boolean;
|
readonly hasPreviousSceneRender: boolean;
|
||||||
|
constructor(sceneLoadAction: Function);
|
||||||
preRender(): void;
|
preRender(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
onBeginTransition(): Promise<any>;
|
onBeginTransition(): void;
|
||||||
protected transitionComplete(): void;
|
protected transitionComplete(): void;
|
||||||
protected loadScene(): Promise<any>;
|
protected loadNextScene(): void;
|
||||||
}
|
}
|
||||||
declare class FadeTransition extends SceneTransition {
|
declare class FadeTransition extends SceneTransition {
|
||||||
fadeToColor: number;
|
fadeToColor: number;
|
||||||
fadeOutDuration: number;
|
fadeOutDuration: number;
|
||||||
private _color;
|
fadeEaseType: Function;
|
||||||
private _toColor;
|
delayBeforeFadeInDuration: number;
|
||||||
private _destinationRect;
|
private _mask;
|
||||||
private _overlayTexture;
|
private _alpha;
|
||||||
constructor(sceneLoadAction: Function);
|
constructor(sceneLoadAction: Function);
|
||||||
|
onBeginTransition(): void;
|
||||||
|
render(): void;
|
||||||
}
|
}
|
||||||
declare class Flags {
|
declare class Flags {
|
||||||
static isFlagSet(self: number, flag: number): boolean;
|
static isFlagSet(self: number, flag: number): boolean;
|
||||||
|
|||||||
@@ -8,41 +8,6 @@ var __extends = (this && this.__extends) || (function () {
|
|||||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
||||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
||||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
||||||
function step(op) {
|
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
|
||||||
while (_) try {
|
|
||||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
||||||
switch (op[0]) {
|
|
||||||
case 0: case 1: t = op; break;
|
|
||||||
case 4: _.label++; return { value: op[1], done: false };
|
|
||||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
||||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
||||||
default:
|
|
||||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
||||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
||||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
||||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
||||||
if (t[2]) _.ops.pop();
|
|
||||||
_.trys.pop(); continue;
|
|
||||||
}
|
|
||||||
op = body.call(thisArg, _);
|
|
||||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
||||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Array.prototype.findIndex = function (predicate) {
|
Array.prototype.findIndex = function (predicate) {
|
||||||
function findIndex(array, predicate) {
|
function findIndex(array, predicate) {
|
||||||
for (var i = 0, len = array.length; i < len; i++) {
|
for (var i = 0, len = array.length; i < len; i++) {
|
||||||
@@ -1094,7 +1059,7 @@ var Entity = (function () {
|
|||||||
};
|
};
|
||||||
Entity.prototype.onRemovedFromScene = function () {
|
Entity.prototype.onRemovedFromScene = function () {
|
||||||
if (this._isDestoryed)
|
if (this._isDestoryed)
|
||||||
this.components.remove;
|
this.components.removeAllComponents();
|
||||||
};
|
};
|
||||||
Entity.prototype.onTransformChanged = function (comp) {
|
Entity.prototype.onTransformChanged = function (comp) {
|
||||||
this.components.onEntityTransformChanged(comp);
|
this.components.onEntityTransformChanged(comp);
|
||||||
@@ -1189,6 +1154,9 @@ var Scene = (function (_super) {
|
|||||||
this._didSceneBegin = false;
|
this._didSceneBegin = false;
|
||||||
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||||
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||||
|
for (var i = 0; i < this._renderers.length; i++) {
|
||||||
|
this._renderers[i].unload();
|
||||||
|
}
|
||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
Physics.clear();
|
Physics.clear();
|
||||||
this.camera.destory();
|
this.camera.destory();
|
||||||
@@ -1196,6 +1164,7 @@ var Scene = (function (_super) {
|
|||||||
this.content.dispose();
|
this.content.dispose();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.end();
|
this.entityProcessors.end();
|
||||||
|
this.unload();
|
||||||
};
|
};
|
||||||
Scene.prototype.onStart = function () {
|
Scene.prototype.onStart = function () {
|
||||||
};
|
};
|
||||||
@@ -1203,6 +1172,7 @@ var Scene = (function (_super) {
|
|||||||
};
|
};
|
||||||
Scene.prototype.onDeactive = function () {
|
Scene.prototype.onDeactive = function () {
|
||||||
};
|
};
|
||||||
|
Scene.prototype.unload = function () { };
|
||||||
Scene.prototype.update = function () {
|
Scene.prototype.update = function () {
|
||||||
this.entities.updateLists();
|
this.entities.updateLists();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
@@ -1225,6 +1195,7 @@ var Scene = (function (_super) {
|
|||||||
var SceneManager = (function () {
|
var SceneManager = (function () {
|
||||||
function SceneManager(stage) {
|
function SceneManager(stage) {
|
||||||
stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this);
|
stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this);
|
||||||
|
SceneManager.stage = stage;
|
||||||
SceneManager.initialize(stage);
|
SceneManager.initialize(stage);
|
||||||
}
|
}
|
||||||
Object.defineProperty(SceneManager, "scene", {
|
Object.defineProperty(SceneManager, "scene", {
|
||||||
@@ -1273,24 +1244,25 @@ var SceneManager = (function () {
|
|||||||
SceneManager.render();
|
SceneManager.render();
|
||||||
};
|
};
|
||||||
SceneManager.render = function () {
|
SceneManager.render = function () {
|
||||||
if (this.sceneTransition)
|
|
||||||
this.sceneTransition.preRender();
|
|
||||||
if (this.sceneTransition) {
|
if (this.sceneTransition) {
|
||||||
if (this._scene && this.sceneTransition.wantsPreviousSceneRender && !this.sceneTransition.hasPreviousSceneRender) {
|
this.sceneTransition.preRender();
|
||||||
this._scene.render();
|
if (this._scene && !this.sceneTransition.hasPreviousSceneRender) {
|
||||||
|
this.scene.render();
|
||||||
this.sceneTransition.onBeginTransition();
|
this.sceneTransition.onBeginTransition();
|
||||||
}
|
}
|
||||||
else if (this._scene && this.sceneTransition.isNewSceneLoaded) {
|
else if (this.sceneTransition) {
|
||||||
this._scene.render();
|
if (this._scene && this.sceneTransition.isNewSceneLoaded) {
|
||||||
|
this._scene.render();
|
||||||
|
}
|
||||||
|
this.sceneTransition.render();
|
||||||
}
|
}
|
||||||
this.sceneTransition.render();
|
|
||||||
}
|
}
|
||||||
else if (this.scene) {
|
else if (this.scene) {
|
||||||
this.scene.render();
|
this.scene.render();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SceneManager.startSceneTransition = function (sceneTransition) {
|
SceneManager.startSceneTransition = function (sceneTransition) {
|
||||||
if (!this.sceneTransition) {
|
if (this.sceneTransition) {
|
||||||
throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
||||||
}
|
}
|
||||||
this.sceneTransition = sceneTransition;
|
this.sceneTransition = sceneTransition;
|
||||||
@@ -2135,6 +2107,10 @@ var SpriteRenderer = (function (_super) {
|
|||||||
this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x;
|
this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x;
|
||||||
this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y;
|
this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y;
|
||||||
};
|
};
|
||||||
|
SpriteRenderer.prototype.onRemovedFromEntity = function () {
|
||||||
|
if (this._bitmap)
|
||||||
|
this.stage.removeChild(this._bitmap);
|
||||||
|
};
|
||||||
return SpriteRenderer;
|
return SpriteRenderer;
|
||||||
}(RenderableComponent));
|
}(RenderableComponent));
|
||||||
var Mover = (function (_super) {
|
var Mover = (function (_super) {
|
||||||
@@ -2805,6 +2781,8 @@ var EntityList = (function () {
|
|||||||
this._entitiesToAdded.length = 0;
|
this._entitiesToAdded.length = 0;
|
||||||
this.updateLists();
|
this.updateLists();
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
|
this._entities[i]._isDestoryed = true;
|
||||||
|
this._entities[i].onRemovedFromScene();
|
||||||
this._entities[i].scene = null;
|
this._entities[i].scene = null;
|
||||||
}
|
}
|
||||||
this._entities.length = 0;
|
this._entities.length = 0;
|
||||||
@@ -2982,6 +2960,7 @@ var Renderer = (function () {
|
|||||||
entities.buffer[i].transform.updateTransform();
|
entities.buffer[i].transform.updateTransform();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Renderer.prototype.unload = function () { };
|
||||||
Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
|
Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
|
||||||
renderable.render(cam);
|
renderable.render(cam);
|
||||||
};
|
};
|
||||||
@@ -3013,14 +2992,9 @@ var ScreenSpaceRenderer = (function (_super) {
|
|||||||
return ScreenSpaceRenderer;
|
return ScreenSpaceRenderer;
|
||||||
}(Renderer));
|
}(Renderer));
|
||||||
var SceneTransition = (function () {
|
var SceneTransition = (function () {
|
||||||
function SceneTransition(sceneLoadAction, wantsPreviousSceneRender) {
|
function SceneTransition(sceneLoadAction) {
|
||||||
if (wantsPreviousSceneRender === void 0) { wantsPreviousSceneRender = true; }
|
|
||||||
this.progress = 0;
|
|
||||||
this.sceneLoadAction = sceneLoadAction;
|
this.sceneLoadAction = sceneLoadAction;
|
||||||
this.wantsPreviousSceneRender = wantsPreviousSceneRender;
|
|
||||||
this.loadsNewScene = sceneLoadAction != null;
|
this.loadsNewScene = sceneLoadAction != null;
|
||||||
if (wantsPreviousSceneRender)
|
|
||||||
this.previousSceneRender = new egret.RenderTexture();
|
|
||||||
}
|
}
|
||||||
Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", {
|
Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", {
|
||||||
get: function () {
|
get: function () {
|
||||||
@@ -3037,58 +3011,60 @@ var SceneTransition = (function () {
|
|||||||
SceneTransition.prototype.render = function () {
|
SceneTransition.prototype.render = function () {
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.onBeginTransition = function () {
|
SceneTransition.prototype.onBeginTransition = function () {
|
||||||
var _this = this;
|
this.loadNextScene();
|
||||||
return new Promise(function (resolve) {
|
this.transitionComplete();
|
||||||
resolve(_this.loadScene());
|
|
||||||
_this.transitionComplete();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.transitionComplete = function () {
|
SceneTransition.prototype.transitionComplete = function () {
|
||||||
SceneManager.sceneTransition = null;
|
SceneManager.sceneTransition = null;
|
||||||
if (this.previousSceneRender) {
|
|
||||||
this.previousSceneRender.dispose();
|
|
||||||
this.previousSceneRender = null;
|
|
||||||
}
|
|
||||||
if (this.onTransitionCompleted) {
|
if (this.onTransitionCompleted) {
|
||||||
this.onTransitionCompleted();
|
this.onTransitionCompleted();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.loadScene = function () {
|
SceneTransition.prototype.loadNextScene = function () {
|
||||||
var _this = this;
|
if (this.onScreenObscured)
|
||||||
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
this.onScreenObscured();
|
||||||
var _a;
|
if (!this.loadsNewScene) {
|
||||||
return __generator(this, function (_b) {
|
this.isNewSceneLoaded = true;
|
||||||
switch (_b.label) {
|
}
|
||||||
case 0:
|
SceneManager.scene = this.sceneLoadAction();
|
||||||
if (this.onScreenObscured)
|
this.isNewSceneLoaded = true;
|
||||||
this.onScreenObscured();
|
|
||||||
if (!this.loadsNewScene) {
|
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
_a = SceneManager;
|
|
||||||
return [4, this.sceneLoadAction()];
|
|
||||||
case 1:
|
|
||||||
_a.scene = _b.sent();
|
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
return [2];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}); });
|
|
||||||
};
|
};
|
||||||
return SceneTransition;
|
return SceneTransition;
|
||||||
}());
|
}());
|
||||||
var FadeTransition = (function (_super) {
|
var FadeTransition = (function (_super) {
|
||||||
__extends(FadeTransition, _super);
|
__extends(FadeTransition, _super);
|
||||||
function FadeTransition(sceneLoadAction) {
|
function FadeTransition(sceneLoadAction) {
|
||||||
var _this = _super.call(this, sceneLoadAction, true) || this;
|
var _this = _super.call(this, sceneLoadAction) || this;
|
||||||
_this.fadeToColor = 0x000000;
|
_this.fadeToColor = 0x000000;
|
||||||
_this.fadeOutDuration = 0.4;
|
_this.fadeOutDuration = 0.4;
|
||||||
_this._color = 0xFFFFFF;
|
_this.fadeEaseType = egret.Ease.quadInOut;
|
||||||
_this._toColor = 0xFFFFFF;
|
_this.delayBeforeFadeInDuration = 0.1;
|
||||||
_this._destinationRect = new Rectangle(0, 0, _this.previousSceneRender.textureWidth, _this.previousSceneRender.textureHeight);
|
_this._alpha = 0;
|
||||||
|
_this._mask = new egret.Shape();
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
|
FadeTransition.prototype.onBeginTransition = function () {
|
||||||
|
var _this = this;
|
||||||
|
this._mask.graphics.beginFill(this.fadeToColor, 1);
|
||||||
|
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||||
|
this._mask.graphics.endFill();
|
||||||
|
SceneManager.stage.addChild(this._mask);
|
||||||
|
egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType)
|
||||||
|
.call(function () {
|
||||||
|
_this.loadNextScene();
|
||||||
|
}).wait(this.delayBeforeFadeInDuration).call(function () {
|
||||||
|
egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () {
|
||||||
|
_this.transitionComplete();
|
||||||
|
SceneManager.stage.removeChild(_this._mask);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
FadeTransition.prototype.render = function () {
|
||||||
|
this._mask.graphics.clear();
|
||||||
|
this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
|
||||||
|
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||||
|
this._mask.graphics.endFill();
|
||||||
|
};
|
||||||
return FadeTransition;
|
return FadeTransition;
|
||||||
}(SceneTransition));
|
}(SceneTransition));
|
||||||
var Flags = (function () {
|
var Flags = (function () {
|
||||||
|
|||||||
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
@@ -104,5 +104,15 @@ class Main extends eui.UILayer {
|
|||||||
// Main.emitter.addObserver(CoreEmitterType.Update, ()=>{
|
// Main.emitter.addObserver(CoreEmitterType.Update, ()=>{
|
||||||
// console.log("update emitter");
|
// console.log("update emitter");
|
||||||
// });
|
// });
|
||||||
|
let button = new eui.Button();
|
||||||
|
button.label = "切换场景";
|
||||||
|
this.stage.addChild(button);
|
||||||
|
button.addEventListener(egret.TouchEvent.TOUCH_TAP, ()=>{
|
||||||
|
SceneManager.startSceneTransition(new FadeTransition(()=>{
|
||||||
|
return new MainScene(this);
|
||||||
|
}));
|
||||||
|
}, this);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
source/bin/framework.d.ts
vendored
27
source/bin/framework.d.ts
vendored
@@ -167,7 +167,7 @@ declare class Entity {
|
|||||||
readonly components: ComponentList;
|
readonly components: ComponentList;
|
||||||
private _updateOrder;
|
private _updateOrder;
|
||||||
private _enabled;
|
private _enabled;
|
||||||
private _isDestoryed;
|
_isDestoryed: boolean;
|
||||||
private _tag;
|
private _tag;
|
||||||
componentBits: BitSet;
|
componentBits: BitSet;
|
||||||
parent: Transform;
|
parent: Transform;
|
||||||
@@ -234,6 +234,7 @@ declare class Scene extends egret.DisplayObjectContainer {
|
|||||||
protected onStart(): void;
|
protected onStart(): void;
|
||||||
protected onActive(): void;
|
protected onActive(): void;
|
||||||
protected onDeactive(): void;
|
protected onDeactive(): void;
|
||||||
|
protected unload(): void;
|
||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
}
|
}
|
||||||
@@ -241,6 +242,7 @@ declare class SceneManager {
|
|||||||
private static _scene;
|
private static _scene;
|
||||||
private static _nextScene;
|
private static _nextScene;
|
||||||
static sceneTransition: SceneTransition;
|
static sceneTransition: SceneTransition;
|
||||||
|
static stage: egret.Stage;
|
||||||
constructor(stage: egret.Stage);
|
constructor(stage: egret.Stage);
|
||||||
static scene: Scene;
|
static scene: Scene;
|
||||||
static initialize(stage: egret.Stage): void;
|
static initialize(stage: egret.Stage): void;
|
||||||
@@ -432,6 +434,7 @@ declare class SpriteRenderer extends RenderableComponent {
|
|||||||
setColor(color: number): void;
|
setColor(color: number): void;
|
||||||
isVisibleFromCamera(camera: Camera): boolean;
|
isVisibleFromCamera(camera: Camera): boolean;
|
||||||
render(camera: Camera): void;
|
render(camera: Camera): void;
|
||||||
|
onRemovedFromEntity(): void;
|
||||||
}
|
}
|
||||||
interface ITriggerListener {
|
interface ITriggerListener {
|
||||||
onTriggerEnter(other: Collider, local: Collider): any;
|
onTriggerEnter(other: Collider, local: Collider): any;
|
||||||
@@ -612,6 +615,7 @@ declare abstract class Renderer {
|
|||||||
onAddedToScene(scene: Scene): void;
|
onAddedToScene(scene: Scene): void;
|
||||||
protected beginRender(cam: Camera): void;
|
protected beginRender(cam: Camera): void;
|
||||||
abstract render(scene: Scene): any;
|
abstract render(scene: Scene): any;
|
||||||
|
unload(): void;
|
||||||
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
|
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
|
||||||
}
|
}
|
||||||
declare class DefaultRenderer extends Renderer {
|
declare class DefaultRenderer extends Renderer {
|
||||||
@@ -628,31 +632,30 @@ declare class ScreenSpaceRenderer extends Renderer {
|
|||||||
render(scene: Scene): void;
|
render(scene: Scene): void;
|
||||||
}
|
}
|
||||||
declare abstract class SceneTransition {
|
declare abstract class SceneTransition {
|
||||||
|
private _hasPreviousSceneRender;
|
||||||
loadsNewScene: boolean;
|
loadsNewScene: boolean;
|
||||||
isNewSceneLoaded: boolean;
|
isNewSceneLoaded: boolean;
|
||||||
wantsPreviousSceneRender: boolean;
|
|
||||||
protected sceneLoadAction: Function;
|
protected sceneLoadAction: Function;
|
||||||
previousSceneRender: egret.RenderTexture;
|
|
||||||
onScreenObscured: Function;
|
onScreenObscured: Function;
|
||||||
onTransitionCompleted: Function;
|
onTransitionCompleted: Function;
|
||||||
progress: number;
|
|
||||||
constructor(sceneLoadAction: Function, wantsPreviousSceneRender?: boolean);
|
|
||||||
private _hasPreviousSceneRender;
|
|
||||||
readonly hasPreviousSceneRender: boolean;
|
readonly hasPreviousSceneRender: boolean;
|
||||||
|
constructor(sceneLoadAction: Function);
|
||||||
preRender(): void;
|
preRender(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
onBeginTransition(): Promise<any>;
|
onBeginTransition(): void;
|
||||||
protected transitionComplete(): void;
|
protected transitionComplete(): void;
|
||||||
protected loadScene(): Promise<any>;
|
protected loadNextScene(): void;
|
||||||
}
|
}
|
||||||
declare class FadeTransition extends SceneTransition {
|
declare class FadeTransition extends SceneTransition {
|
||||||
fadeToColor: number;
|
fadeToColor: number;
|
||||||
fadeOutDuration: number;
|
fadeOutDuration: number;
|
||||||
private _color;
|
fadeEaseType: Function;
|
||||||
private _toColor;
|
delayBeforeFadeInDuration: number;
|
||||||
private _destinationRect;
|
private _mask;
|
||||||
private _overlayTexture;
|
private _alpha;
|
||||||
constructor(sceneLoadAction: Function);
|
constructor(sceneLoadAction: Function);
|
||||||
|
onBeginTransition(): void;
|
||||||
|
render(): void;
|
||||||
}
|
}
|
||||||
declare class Flags {
|
declare class Flags {
|
||||||
static isFlagSet(self: number, flag: number): boolean;
|
static isFlagSet(self: number, flag: number): boolean;
|
||||||
|
|||||||
@@ -8,41 +8,6 @@ var __extends = (this && this.__extends) || (function () {
|
|||||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
|
||||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
||||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
||||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
||||||
});
|
|
||||||
};
|
|
||||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
||||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
||||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
||||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
||||||
function step(op) {
|
|
||||||
if (f) throw new TypeError("Generator is already executing.");
|
|
||||||
while (_) try {
|
|
||||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
||||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
||||||
switch (op[0]) {
|
|
||||||
case 0: case 1: t = op; break;
|
|
||||||
case 4: _.label++; return { value: op[1], done: false };
|
|
||||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
||||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
||||||
default:
|
|
||||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
||||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
||||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
||||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
||||||
if (t[2]) _.ops.pop();
|
|
||||||
_.trys.pop(); continue;
|
|
||||||
}
|
|
||||||
op = body.call(thisArg, _);
|
|
||||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
||||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Array.prototype.findIndex = function (predicate) {
|
Array.prototype.findIndex = function (predicate) {
|
||||||
function findIndex(array, predicate) {
|
function findIndex(array, predicate) {
|
||||||
for (var i = 0, len = array.length; i < len; i++) {
|
for (var i = 0, len = array.length; i < len; i++) {
|
||||||
@@ -1094,7 +1059,7 @@ var Entity = (function () {
|
|||||||
};
|
};
|
||||||
Entity.prototype.onRemovedFromScene = function () {
|
Entity.prototype.onRemovedFromScene = function () {
|
||||||
if (this._isDestoryed)
|
if (this._isDestoryed)
|
||||||
this.components.remove;
|
this.components.removeAllComponents();
|
||||||
};
|
};
|
||||||
Entity.prototype.onTransformChanged = function (comp) {
|
Entity.prototype.onTransformChanged = function (comp) {
|
||||||
this.components.onEntityTransformChanged(comp);
|
this.components.onEntityTransformChanged(comp);
|
||||||
@@ -1189,6 +1154,9 @@ var Scene = (function (_super) {
|
|||||||
this._didSceneBegin = false;
|
this._didSceneBegin = false;
|
||||||
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||||
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||||
|
for (var i = 0; i < this._renderers.length; i++) {
|
||||||
|
this._renderers[i].unload();
|
||||||
|
}
|
||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
Physics.clear();
|
Physics.clear();
|
||||||
this.camera.destory();
|
this.camera.destory();
|
||||||
@@ -1196,6 +1164,7 @@ var Scene = (function (_super) {
|
|||||||
this.content.dispose();
|
this.content.dispose();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.end();
|
this.entityProcessors.end();
|
||||||
|
this.unload();
|
||||||
};
|
};
|
||||||
Scene.prototype.onStart = function () {
|
Scene.prototype.onStart = function () {
|
||||||
};
|
};
|
||||||
@@ -1203,6 +1172,7 @@ var Scene = (function (_super) {
|
|||||||
};
|
};
|
||||||
Scene.prototype.onDeactive = function () {
|
Scene.prototype.onDeactive = function () {
|
||||||
};
|
};
|
||||||
|
Scene.prototype.unload = function () { };
|
||||||
Scene.prototype.update = function () {
|
Scene.prototype.update = function () {
|
||||||
this.entities.updateLists();
|
this.entities.updateLists();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
@@ -1225,6 +1195,7 @@ var Scene = (function (_super) {
|
|||||||
var SceneManager = (function () {
|
var SceneManager = (function () {
|
||||||
function SceneManager(stage) {
|
function SceneManager(stage) {
|
||||||
stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this);
|
stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this);
|
||||||
|
SceneManager.stage = stage;
|
||||||
SceneManager.initialize(stage);
|
SceneManager.initialize(stage);
|
||||||
}
|
}
|
||||||
Object.defineProperty(SceneManager, "scene", {
|
Object.defineProperty(SceneManager, "scene", {
|
||||||
@@ -1273,24 +1244,25 @@ var SceneManager = (function () {
|
|||||||
SceneManager.render();
|
SceneManager.render();
|
||||||
};
|
};
|
||||||
SceneManager.render = function () {
|
SceneManager.render = function () {
|
||||||
if (this.sceneTransition)
|
|
||||||
this.sceneTransition.preRender();
|
|
||||||
if (this.sceneTransition) {
|
if (this.sceneTransition) {
|
||||||
if (this._scene && this.sceneTransition.wantsPreviousSceneRender && !this.sceneTransition.hasPreviousSceneRender) {
|
this.sceneTransition.preRender();
|
||||||
this._scene.render();
|
if (this._scene && !this.sceneTransition.hasPreviousSceneRender) {
|
||||||
|
this.scene.render();
|
||||||
this.sceneTransition.onBeginTransition();
|
this.sceneTransition.onBeginTransition();
|
||||||
}
|
}
|
||||||
else if (this._scene && this.sceneTransition.isNewSceneLoaded) {
|
else if (this.sceneTransition) {
|
||||||
this._scene.render();
|
if (this._scene && this.sceneTransition.isNewSceneLoaded) {
|
||||||
|
this._scene.render();
|
||||||
|
}
|
||||||
|
this.sceneTransition.render();
|
||||||
}
|
}
|
||||||
this.sceneTransition.render();
|
|
||||||
}
|
}
|
||||||
else if (this.scene) {
|
else if (this.scene) {
|
||||||
this.scene.render();
|
this.scene.render();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SceneManager.startSceneTransition = function (sceneTransition) {
|
SceneManager.startSceneTransition = function (sceneTransition) {
|
||||||
if (!this.sceneTransition) {
|
if (this.sceneTransition) {
|
||||||
throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
||||||
}
|
}
|
||||||
this.sceneTransition = sceneTransition;
|
this.sceneTransition = sceneTransition;
|
||||||
@@ -2135,6 +2107,10 @@ var SpriteRenderer = (function (_super) {
|
|||||||
this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x;
|
this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x;
|
||||||
this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y;
|
this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y;
|
||||||
};
|
};
|
||||||
|
SpriteRenderer.prototype.onRemovedFromEntity = function () {
|
||||||
|
if (this._bitmap)
|
||||||
|
this.stage.removeChild(this._bitmap);
|
||||||
|
};
|
||||||
return SpriteRenderer;
|
return SpriteRenderer;
|
||||||
}(RenderableComponent));
|
}(RenderableComponent));
|
||||||
var Mover = (function (_super) {
|
var Mover = (function (_super) {
|
||||||
@@ -2805,6 +2781,8 @@ var EntityList = (function () {
|
|||||||
this._entitiesToAdded.length = 0;
|
this._entitiesToAdded.length = 0;
|
||||||
this.updateLists();
|
this.updateLists();
|
||||||
for (var i = 0; i < this._entities.length; i++) {
|
for (var i = 0; i < this._entities.length; i++) {
|
||||||
|
this._entities[i]._isDestoryed = true;
|
||||||
|
this._entities[i].onRemovedFromScene();
|
||||||
this._entities[i].scene = null;
|
this._entities[i].scene = null;
|
||||||
}
|
}
|
||||||
this._entities.length = 0;
|
this._entities.length = 0;
|
||||||
@@ -2982,6 +2960,7 @@ var Renderer = (function () {
|
|||||||
entities.buffer[i].transform.updateTransform();
|
entities.buffer[i].transform.updateTransform();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Renderer.prototype.unload = function () { };
|
||||||
Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
|
Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
|
||||||
renderable.render(cam);
|
renderable.render(cam);
|
||||||
};
|
};
|
||||||
@@ -3013,14 +2992,9 @@ var ScreenSpaceRenderer = (function (_super) {
|
|||||||
return ScreenSpaceRenderer;
|
return ScreenSpaceRenderer;
|
||||||
}(Renderer));
|
}(Renderer));
|
||||||
var SceneTransition = (function () {
|
var SceneTransition = (function () {
|
||||||
function SceneTransition(sceneLoadAction, wantsPreviousSceneRender) {
|
function SceneTransition(sceneLoadAction) {
|
||||||
if (wantsPreviousSceneRender === void 0) { wantsPreviousSceneRender = true; }
|
|
||||||
this.progress = 0;
|
|
||||||
this.sceneLoadAction = sceneLoadAction;
|
this.sceneLoadAction = sceneLoadAction;
|
||||||
this.wantsPreviousSceneRender = wantsPreviousSceneRender;
|
|
||||||
this.loadsNewScene = sceneLoadAction != null;
|
this.loadsNewScene = sceneLoadAction != null;
|
||||||
if (wantsPreviousSceneRender)
|
|
||||||
this.previousSceneRender = new egret.RenderTexture();
|
|
||||||
}
|
}
|
||||||
Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", {
|
Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", {
|
||||||
get: function () {
|
get: function () {
|
||||||
@@ -3037,58 +3011,60 @@ var SceneTransition = (function () {
|
|||||||
SceneTransition.prototype.render = function () {
|
SceneTransition.prototype.render = function () {
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.onBeginTransition = function () {
|
SceneTransition.prototype.onBeginTransition = function () {
|
||||||
var _this = this;
|
this.loadNextScene();
|
||||||
return new Promise(function (resolve) {
|
this.transitionComplete();
|
||||||
resolve(_this.loadScene());
|
|
||||||
_this.transitionComplete();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.transitionComplete = function () {
|
SceneTransition.prototype.transitionComplete = function () {
|
||||||
SceneManager.sceneTransition = null;
|
SceneManager.sceneTransition = null;
|
||||||
if (this.previousSceneRender) {
|
|
||||||
this.previousSceneRender.dispose();
|
|
||||||
this.previousSceneRender = null;
|
|
||||||
}
|
|
||||||
if (this.onTransitionCompleted) {
|
if (this.onTransitionCompleted) {
|
||||||
this.onTransitionCompleted();
|
this.onTransitionCompleted();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
SceneTransition.prototype.loadScene = function () {
|
SceneTransition.prototype.loadNextScene = function () {
|
||||||
var _this = this;
|
if (this.onScreenObscured)
|
||||||
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
this.onScreenObscured();
|
||||||
var _a;
|
if (!this.loadsNewScene) {
|
||||||
return __generator(this, function (_b) {
|
this.isNewSceneLoaded = true;
|
||||||
switch (_b.label) {
|
}
|
||||||
case 0:
|
SceneManager.scene = this.sceneLoadAction();
|
||||||
if (this.onScreenObscured)
|
this.isNewSceneLoaded = true;
|
||||||
this.onScreenObscured();
|
|
||||||
if (!this.loadsNewScene) {
|
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
_a = SceneManager;
|
|
||||||
return [4, this.sceneLoadAction()];
|
|
||||||
case 1:
|
|
||||||
_a.scene = _b.sent();
|
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
return [2];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}); });
|
|
||||||
};
|
};
|
||||||
return SceneTransition;
|
return SceneTransition;
|
||||||
}());
|
}());
|
||||||
var FadeTransition = (function (_super) {
|
var FadeTransition = (function (_super) {
|
||||||
__extends(FadeTransition, _super);
|
__extends(FadeTransition, _super);
|
||||||
function FadeTransition(sceneLoadAction) {
|
function FadeTransition(sceneLoadAction) {
|
||||||
var _this = _super.call(this, sceneLoadAction, true) || this;
|
var _this = _super.call(this, sceneLoadAction) || this;
|
||||||
_this.fadeToColor = 0x000000;
|
_this.fadeToColor = 0x000000;
|
||||||
_this.fadeOutDuration = 0.4;
|
_this.fadeOutDuration = 0.4;
|
||||||
_this._color = 0xFFFFFF;
|
_this.fadeEaseType = egret.Ease.quadInOut;
|
||||||
_this._toColor = 0xFFFFFF;
|
_this.delayBeforeFadeInDuration = 0.1;
|
||||||
_this._destinationRect = new Rectangle(0, 0, _this.previousSceneRender.textureWidth, _this.previousSceneRender.textureHeight);
|
_this._alpha = 0;
|
||||||
|
_this._mask = new egret.Shape();
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
|
FadeTransition.prototype.onBeginTransition = function () {
|
||||||
|
var _this = this;
|
||||||
|
this._mask.graphics.beginFill(this.fadeToColor, 1);
|
||||||
|
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||||
|
this._mask.graphics.endFill();
|
||||||
|
SceneManager.stage.addChild(this._mask);
|
||||||
|
egret.Tween.get(this).to({ _alpha: 1 }, this.fadeOutDuration * 1000, this.fadeEaseType)
|
||||||
|
.call(function () {
|
||||||
|
_this.loadNextScene();
|
||||||
|
}).wait(this.delayBeforeFadeInDuration).call(function () {
|
||||||
|
egret.Tween.get(_this).to({ _alpha: 0 }, _this.fadeOutDuration * 1000, _this.fadeEaseType).call(function () {
|
||||||
|
_this.transitionComplete();
|
||||||
|
SceneManager.stage.removeChild(_this._mask);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
FadeTransition.prototype.render = function () {
|
||||||
|
this._mask.graphics.clear();
|
||||||
|
this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
|
||||||
|
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||||
|
this._mask.graphics.endFill();
|
||||||
|
};
|
||||||
return FadeTransition;
|
return FadeTransition;
|
||||||
}(SceneTransition));
|
}(SceneTransition));
|
||||||
var Flags = (function () {
|
var Flags = (function () {
|
||||||
|
|||||||
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
@@ -82,4 +82,9 @@ class SpriteRenderer extends RenderableComponent {
|
|||||||
this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x;
|
this._bitmap.scaleX = this.entity.transform.scale.x * camera.transform.scale.x;
|
||||||
this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y;
|
this._bitmap.scaleY = this.entity.transform.scale.y * camera.transform.scale.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public onRemovedFromEntity(){
|
||||||
|
if (this._bitmap)
|
||||||
|
this.stage.removeChild(this._bitmap);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,7 +11,7 @@ class Entity {
|
|||||||
public readonly components: ComponentList;
|
public readonly components: ComponentList;
|
||||||
private _updateOrder: number = 0;
|
private _updateOrder: number = 0;
|
||||||
private _enabled: boolean = true;
|
private _enabled: boolean = true;
|
||||||
private _isDestoryed: boolean;
|
public _isDestoryed: boolean;
|
||||||
private _tag: number = 0;
|
private _tag: number = 0;
|
||||||
|
|
||||||
public componentBits: BitSet;
|
public componentBits: BitSet;
|
||||||
@@ -253,7 +253,7 @@ class Entity {
|
|||||||
|
|
||||||
public onRemovedFromScene(){
|
public onRemovedFromScene(){
|
||||||
if (this._isDestoryed)
|
if (this._isDestoryed)
|
||||||
this.components.remove
|
this.components.removeAllComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
public onTransformChanged(comp: ComponentTransform){
|
public onTransformChanged(comp: ComponentTransform){
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ class Scene extends egret.DisplayObjectContainer {
|
|||||||
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, this);
|
||||||
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
this.removeEventListener(egret.Event.ACTIVATE, this.onActive, this);
|
||||||
|
|
||||||
|
for (let i = 0; i < this._renderers.length; i ++){
|
||||||
|
this._renderers[i].unload();
|
||||||
|
}
|
||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
|
|
||||||
Physics.clear();
|
Physics.clear();
|
||||||
@@ -127,6 +130,8 @@ class Scene extends egret.DisplayObjectContainer {
|
|||||||
|
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.end();
|
this.entityProcessors.end();
|
||||||
|
|
||||||
|
this.unload();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onStart(){
|
protected onStart(){
|
||||||
@@ -143,6 +148,8 @@ class Scene extends egret.DisplayObjectContainer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected unload(){ }
|
||||||
|
|
||||||
public update() {
|
public update() {
|
||||||
this.entities.updateLists();
|
this.entities.updateLists();
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ class SceneManager {
|
|||||||
private static _scene: Scene;
|
private static _scene: Scene;
|
||||||
private static _nextScene: Scene;
|
private static _nextScene: Scene;
|
||||||
public static sceneTransition: SceneTransition;
|
public static sceneTransition: SceneTransition;
|
||||||
|
public static stage: egret.Stage;
|
||||||
|
|
||||||
constructor(stage: egret.Stage) {
|
constructor(stage: egret.Stage) {
|
||||||
stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this);
|
stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this);
|
||||||
|
|
||||||
|
SceneManager.stage = stage;
|
||||||
SceneManager.initialize(stage);
|
SceneManager.initialize(stage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,18 +64,19 @@ class SceneManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static render() {
|
public static render() {
|
||||||
if (this.sceneTransition)
|
if (this.sceneTransition){
|
||||||
this.sceneTransition.preRender();
|
this.sceneTransition.preRender();
|
||||||
|
|
||||||
if (this.sceneTransition) {
|
if (this._scene && !this.sceneTransition.hasPreviousSceneRender){
|
||||||
if (this._scene && this.sceneTransition.wantsPreviousSceneRender && !this.sceneTransition.hasPreviousSceneRender) {
|
this.scene.render();
|
||||||
this._scene.render();
|
|
||||||
this.sceneTransition.onBeginTransition();
|
this.sceneTransition.onBeginTransition();
|
||||||
} else if (this._scene && this.sceneTransition.isNewSceneLoaded) {
|
} else if (this.sceneTransition) {
|
||||||
this._scene.render();
|
if (this._scene && this.sceneTransition.isNewSceneLoaded) {
|
||||||
|
this._scene.render();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sceneTransition.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sceneTransition.render();
|
|
||||||
} else if (this.scene) {
|
} else if (this.scene) {
|
||||||
this.scene.render();
|
this.scene.render();
|
||||||
}
|
}
|
||||||
@@ -84,7 +87,7 @@ class SceneManager {
|
|||||||
* @param sceneTransition
|
* @param sceneTransition
|
||||||
*/
|
*/
|
||||||
public static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T {
|
public static startSceneTransition<T extends SceneTransition>(sceneTransition: T): T {
|
||||||
if (!this.sceneTransition) {
|
if (this.sceneTransition) {
|
||||||
throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ class EntityList{
|
|||||||
this.updateLists();
|
this.updateLists();
|
||||||
|
|
||||||
for (let i = 0; i < this._entities.length; i ++){
|
for (let i = 0; i < this._entities.length; i ++){
|
||||||
|
this._entities[i]._isDestoryed = true;
|
||||||
|
this._entities[i].onRemovedFromScene();
|
||||||
this._entities[i].scene = null;
|
this._entities[i].scene = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ abstract class Renderer {
|
|||||||
* @param scene
|
* @param scene
|
||||||
*/
|
*/
|
||||||
public abstract render(scene: Scene);
|
public abstract render(scene: Scene);
|
||||||
|
|
||||||
|
public unload(){ }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -2,32 +2,37 @@
|
|||||||
class FadeTransition extends SceneTransition {
|
class FadeTransition extends SceneTransition {
|
||||||
public fadeToColor: number = 0x000000;
|
public fadeToColor: number = 0x000000;
|
||||||
public fadeOutDuration = 0.4;
|
public fadeOutDuration = 0.4;
|
||||||
private _color: number = 0xFFFFFF;
|
public fadeEaseType: Function = egret.Ease.quadInOut;
|
||||||
private _toColor: number = 0xFFFFFF;
|
public delayBeforeFadeInDuration = 0.1;
|
||||||
private _destinationRect: Rectangle;
|
private _mask: egret.Shape;
|
||||||
private _overlayTexture: egret.RenderTexture;
|
private _alpha: number = 0;
|
||||||
|
|
||||||
constructor(sceneLoadAction: Function){
|
constructor(sceneLoadAction: Function) {
|
||||||
super(sceneLoadAction, true);
|
super(sceneLoadAction);
|
||||||
this._destinationRect = new Rectangle(0, 0, this.previousSceneRender.textureWidth, this.previousSceneRender.textureHeight);
|
this._mask = new egret.Shape();
|
||||||
}
|
}
|
||||||
|
|
||||||
// public onBeginTransition(){
|
public onBeginTransition() {
|
||||||
// this._overlayTexture = new egret.RenderTexture();
|
this._mask.graphics.beginFill(this.fadeToColor, 1);
|
||||||
// let shape = new egret.Shape();
|
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||||
// shape.graphics.beginFill(0xFFFFFF, 1);
|
this._mask.graphics.endFill();
|
||||||
// shape.graphics.drawRect(0, 0, 1, 1);
|
SceneManager.stage.addChild(this._mask);
|
||||||
// shape.graphics.endFill();
|
|
||||||
// this._overlayTexture.drawToTexture(shape);
|
|
||||||
|
|
||||||
// let elapsed = 0;
|
egret.Tween.get(this).to({ _alpha: 1}, this.fadeOutDuration * 1000, this.fadeEaseType)
|
||||||
// let _toColor;
|
.call(() => {
|
||||||
// while (elapsed < this.fadeOutDuration){
|
this.loadNextScene();
|
||||||
// elapsed += Time.deltaTime;
|
}).wait(this.delayBeforeFadeInDuration).call(() => {
|
||||||
|
egret.Tween.get(this).to({ _alpha: 0 }, this.fadeOutDuration * 1000, this.fadeEaseType).call(() => {
|
||||||
// // egret.Tween.get(this).to({_color: this._toColor, })
|
this.transitionComplete();
|
||||||
// }
|
SceneManager.stage.removeChild(this._mask);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public render(){
|
||||||
// }
|
this._mask.graphics.clear();
|
||||||
|
this._mask.graphics.beginFill(this.fadeToColor, this._alpha);
|
||||||
|
this._mask.graphics.drawRect(0, 0, SceneManager.stage.stageWidth, SceneManager.stage.stageHeight);
|
||||||
|
this._mask.graphics.endFill();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
|
* SceneTransition用于从一个场景过渡到另一个场景或在一个有效果的场景中过渡
|
||||||
*/
|
*/
|
||||||
abstract class SceneTransition {
|
abstract class SceneTransition {
|
||||||
|
private _hasPreviousSceneRender: boolean;
|
||||||
/** 是否加载新场景的标志 */
|
/** 是否加载新场景的标志 */
|
||||||
public loadsNewScene: boolean;
|
public loadsNewScene: boolean;
|
||||||
/**
|
/**
|
||||||
@@ -9,33 +10,15 @@ abstract class SceneTransition {
|
|||||||
* 对于场景过渡,isNewSceneLoaded应该在中点设置为true,这就标识一个新的场景被加载了。
|
* 对于场景过渡,isNewSceneLoaded应该在中点设置为true,这就标识一个新的场景被加载了。
|
||||||
*/
|
*/
|
||||||
public isNewSceneLoaded: boolean;
|
public isNewSceneLoaded: boolean;
|
||||||
/**
|
|
||||||
* 如果为true
|
|
||||||
* 会将之前的场景渲染到previousSceneRender中,这样你就可以在转换时使用它
|
|
||||||
*/
|
|
||||||
public wantsPreviousSceneRender: boolean;
|
|
||||||
/** 返回新加载场景的函数 */
|
/** 返回新加载场景的函数 */
|
||||||
protected sceneLoadAction: Function;
|
protected sceneLoadAction: Function;
|
||||||
/** 包含上一个场景的最后渲染。可以用来在加载新场景时模糊屏幕。 */
|
|
||||||
public previousSceneRender: egret.RenderTexture;
|
|
||||||
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
|
/** 在loadNextScene执行时调用。这在进行场景间过渡时很有用,这样你就知道什么时候可以更多地使用相机或者重置任何实体 */
|
||||||
public onScreenObscured: Function;
|
public onScreenObscured: Function;
|
||||||
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
|
/** 当转换完成执行时调用,以便可以调用其他工作,比如启动另一个转换。 */
|
||||||
public onTransitionCompleted: Function;
|
public onTransitionCompleted: Function;
|
||||||
public progress: number = 0;
|
|
||||||
|
|
||||||
constructor(sceneLoadAction: Function, wantsPreviousSceneRender: boolean = true) {
|
public get hasPreviousSceneRender(){
|
||||||
this.sceneLoadAction = sceneLoadAction;
|
if (!this._hasPreviousSceneRender){
|
||||||
this.wantsPreviousSceneRender = wantsPreviousSceneRender;
|
|
||||||
this.loadsNewScene = sceneLoadAction != null;
|
|
||||||
|
|
||||||
if (wantsPreviousSceneRender)
|
|
||||||
this.previousSceneRender = new egret.RenderTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
private _hasPreviousSceneRender;
|
|
||||||
public get hasPreviousSceneRender() {
|
|
||||||
if (!this._hasPreviousSceneRender) {
|
|
||||||
this._hasPreviousSceneRender = true;
|
this._hasPreviousSceneRender = true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -43,44 +26,39 @@ abstract class SceneTransition {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public preRender() { }
|
constructor(sceneLoadAction: Function) {
|
||||||
|
this.sceneLoadAction = sceneLoadAction;
|
||||||
public render(){
|
this.loadsNewScene = sceneLoadAction != null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public onBeginTransition(): Promise<any> {
|
public preRender() { }
|
||||||
return new Promise((resolve) => {
|
|
||||||
resolve(this.loadScene());
|
public render() {
|
||||||
this.transitionComplete();
|
|
||||||
});
|
}
|
||||||
|
|
||||||
|
public onBeginTransition() {
|
||||||
|
this.loadNextScene();
|
||||||
|
this.transitionComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected transitionComplete() {
|
protected transitionComplete() {
|
||||||
SceneManager.sceneTransition = null;
|
SceneManager.sceneTransition = null;
|
||||||
|
|
||||||
if (this.previousSceneRender){
|
if (this.onTransitionCompleted) {
|
||||||
this.previousSceneRender.dispose();
|
|
||||||
this.previousSceneRender = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.onTransitionCompleted){
|
|
||||||
this.onTransitionCompleted();
|
this.onTransitionCompleted();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected loadScene(): Promise<any> {
|
protected loadNextScene() {
|
||||||
return new Promise(async (resolve) => {
|
if (this.onScreenObscured)
|
||||||
if (this.onScreenObscured)
|
this.onScreenObscured();
|
||||||
this.onScreenObscured();
|
|
||||||
|
|
||||||
if (!this.loadsNewScene) {
|
if (!this.loadsNewScene) {
|
||||||
this.isNewSceneLoaded = true;
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
|
|
||||||
SceneManager.scene = await this.sceneLoadAction();
|
|
||||||
this.isNewSceneLoaded = true;
|
this.isNewSceneLoaded = true;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
SceneManager.scene = this.sceneLoadAction();
|
||||||
|
this.isNewSceneLoaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user