完善渐隐场景转换
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;
|
||||
private _updateOrder;
|
||||
private _enabled;
|
||||
private _isDestoryed;
|
||||
_isDestoryed: boolean;
|
||||
private _tag;
|
||||
componentBits: BitSet;
|
||||
parent: Transform;
|
||||
@@ -234,6 +234,7 @@ declare class Scene extends egret.DisplayObjectContainer {
|
||||
protected onStart(): void;
|
||||
protected onActive(): void;
|
||||
protected onDeactive(): void;
|
||||
protected unload(): void;
|
||||
update(): void;
|
||||
render(): void;
|
||||
}
|
||||
@@ -241,6 +242,7 @@ declare class SceneManager {
|
||||
private static _scene;
|
||||
private static _nextScene;
|
||||
static sceneTransition: SceneTransition;
|
||||
static stage: egret.Stage;
|
||||
constructor(stage: egret.Stage);
|
||||
static scene: Scene;
|
||||
static initialize(stage: egret.Stage): void;
|
||||
@@ -432,6 +434,7 @@ declare class SpriteRenderer extends RenderableComponent {
|
||||
setColor(color: number): void;
|
||||
isVisibleFromCamera(camera: Camera): boolean;
|
||||
render(camera: Camera): void;
|
||||
onRemovedFromEntity(): void;
|
||||
}
|
||||
interface ITriggerListener {
|
||||
onTriggerEnter(other: Collider, local: Collider): any;
|
||||
@@ -612,6 +615,7 @@ declare abstract class Renderer {
|
||||
onAddedToScene(scene: Scene): void;
|
||||
protected beginRender(cam: Camera): void;
|
||||
abstract render(scene: Scene): any;
|
||||
unload(): void;
|
||||
protected renderAfterStateCheck(renderable: IRenderable, cam: Camera): void;
|
||||
}
|
||||
declare class DefaultRenderer extends Renderer {
|
||||
@@ -628,31 +632,30 @@ declare class ScreenSpaceRenderer extends Renderer {
|
||||
render(scene: Scene): void;
|
||||
}
|
||||
declare abstract class SceneTransition {
|
||||
private _hasPreviousSceneRender;
|
||||
loadsNewScene: boolean;
|
||||
isNewSceneLoaded: boolean;
|
||||
wantsPreviousSceneRender: boolean;
|
||||
protected sceneLoadAction: Function;
|
||||
previousSceneRender: egret.RenderTexture;
|
||||
onScreenObscured: Function;
|
||||
onTransitionCompleted: Function;
|
||||
progress: number;
|
||||
constructor(sceneLoadAction: Function, wantsPreviousSceneRender?: boolean);
|
||||
private _hasPreviousSceneRender;
|
||||
readonly hasPreviousSceneRender: boolean;
|
||||
constructor(sceneLoadAction: Function);
|
||||
preRender(): void;
|
||||
render(): void;
|
||||
onBeginTransition(): Promise<any>;
|
||||
onBeginTransition(): void;
|
||||
protected transitionComplete(): void;
|
||||
protected loadScene(): Promise<any>;
|
||||
protected loadNextScene(): void;
|
||||
}
|
||||
declare class FadeTransition extends SceneTransition {
|
||||
fadeToColor: number;
|
||||
fadeOutDuration: number;
|
||||
private _color;
|
||||
private _toColor;
|
||||
private _destinationRect;
|
||||
private _overlayTexture;
|
||||
fadeEaseType: Function;
|
||||
delayBeforeFadeInDuration: number;
|
||||
private _mask;
|
||||
private _alpha;
|
||||
constructor(sceneLoadAction: Function);
|
||||
onBeginTransition(): void;
|
||||
render(): void;
|
||||
}
|
||||
declare class Flags {
|
||||
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 __());
|
||||
};
|
||||
})();
|
||||
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) {
|
||||
function findIndex(array, predicate) {
|
||||
for (var i = 0, len = array.length; i < len; i++) {
|
||||
@@ -1094,7 +1059,7 @@ var Entity = (function () {
|
||||
};
|
||||
Entity.prototype.onRemovedFromScene = function () {
|
||||
if (this._isDestoryed)
|
||||
this.components.remove;
|
||||
this.components.removeAllComponents();
|
||||
};
|
||||
Entity.prototype.onTransformChanged = function (comp) {
|
||||
this.components.onEntityTransformChanged(comp);
|
||||
@@ -1189,6 +1154,9 @@ var Scene = (function (_super) {
|
||||
this._didSceneBegin = false;
|
||||
this.removeEventListener(egret.Event.DEACTIVATE, this.onDeactive, 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();
|
||||
Physics.clear();
|
||||
this.camera.destory();
|
||||
@@ -1196,6 +1164,7 @@ var Scene = (function (_super) {
|
||||
this.content.dispose();
|
||||
if (this.entityProcessors)
|
||||
this.entityProcessors.end();
|
||||
this.unload();
|
||||
};
|
||||
Scene.prototype.onStart = function () {
|
||||
};
|
||||
@@ -1203,6 +1172,7 @@ var Scene = (function (_super) {
|
||||
};
|
||||
Scene.prototype.onDeactive = function () {
|
||||
};
|
||||
Scene.prototype.unload = function () { };
|
||||
Scene.prototype.update = function () {
|
||||
this.entities.updateLists();
|
||||
if (this.entityProcessors)
|
||||
@@ -1225,6 +1195,7 @@ var Scene = (function (_super) {
|
||||
var SceneManager = (function () {
|
||||
function SceneManager(stage) {
|
||||
stage.addEventListener(egret.Event.ENTER_FRAME, SceneManager.update, this);
|
||||
SceneManager.stage = stage;
|
||||
SceneManager.initialize(stage);
|
||||
}
|
||||
Object.defineProperty(SceneManager, "scene", {
|
||||
@@ -1273,24 +1244,25 @@ var SceneManager = (function () {
|
||||
SceneManager.render();
|
||||
};
|
||||
SceneManager.render = function () {
|
||||
if (this.sceneTransition)
|
||||
this.sceneTransition.preRender();
|
||||
if (this.sceneTransition) {
|
||||
if (this._scene && this.sceneTransition.wantsPreviousSceneRender && !this.sceneTransition.hasPreviousSceneRender) {
|
||||
this._scene.render();
|
||||
this.sceneTransition.preRender();
|
||||
if (this._scene && !this.sceneTransition.hasPreviousSceneRender) {
|
||||
this.scene.render();
|
||||
this.sceneTransition.onBeginTransition();
|
||||
}
|
||||
else if (this._scene && this.sceneTransition.isNewSceneLoaded) {
|
||||
this._scene.render();
|
||||
else if (this.sceneTransition) {
|
||||
if (this._scene && this.sceneTransition.isNewSceneLoaded) {
|
||||
this._scene.render();
|
||||
}
|
||||
this.sceneTransition.render();
|
||||
}
|
||||
this.sceneTransition.render();
|
||||
}
|
||||
else if (this.scene) {
|
||||
this.scene.render();
|
||||
}
|
||||
};
|
||||
SceneManager.startSceneTransition = function (sceneTransition) {
|
||||
if (!this.sceneTransition) {
|
||||
if (this.sceneTransition) {
|
||||
throw new Error("在前一个场景完成之前,不能开始一个新的场景转换。");
|
||||
}
|
||||
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.scaleY = this.entity.transform.scale.y * camera.transform.scale.y;
|
||||
};
|
||||
SpriteRenderer.prototype.onRemovedFromEntity = function () {
|
||||
if (this._bitmap)
|
||||
this.stage.removeChild(this._bitmap);
|
||||
};
|
||||
return SpriteRenderer;
|
||||
}(RenderableComponent));
|
||||
var Mover = (function (_super) {
|
||||
@@ -2805,6 +2781,8 @@ var EntityList = (function () {
|
||||
this._entitiesToAdded.length = 0;
|
||||
this.updateLists();
|
||||
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.length = 0;
|
||||
@@ -2982,6 +2960,7 @@ var Renderer = (function () {
|
||||
entities.buffer[i].transform.updateTransform();
|
||||
}
|
||||
};
|
||||
Renderer.prototype.unload = function () { };
|
||||
Renderer.prototype.renderAfterStateCheck = function (renderable, cam) {
|
||||
renderable.render(cam);
|
||||
};
|
||||
@@ -3013,14 +2992,9 @@ var ScreenSpaceRenderer = (function (_super) {
|
||||
return ScreenSpaceRenderer;
|
||||
}(Renderer));
|
||||
var SceneTransition = (function () {
|
||||
function SceneTransition(sceneLoadAction, wantsPreviousSceneRender) {
|
||||
if (wantsPreviousSceneRender === void 0) { wantsPreviousSceneRender = true; }
|
||||
this.progress = 0;
|
||||
function SceneTransition(sceneLoadAction) {
|
||||
this.sceneLoadAction = sceneLoadAction;
|
||||
this.wantsPreviousSceneRender = wantsPreviousSceneRender;
|
||||
this.loadsNewScene = sceneLoadAction != null;
|
||||
if (wantsPreviousSceneRender)
|
||||
this.previousSceneRender = new egret.RenderTexture();
|
||||
}
|
||||
Object.defineProperty(SceneTransition.prototype, "hasPreviousSceneRender", {
|
||||
get: function () {
|
||||
@@ -3037,58 +3011,60 @@ var SceneTransition = (function () {
|
||||
SceneTransition.prototype.render = function () {
|
||||
};
|
||||
SceneTransition.prototype.onBeginTransition = function () {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve) {
|
||||
resolve(_this.loadScene());
|
||||
_this.transitionComplete();
|
||||
});
|
||||
this.loadNextScene();
|
||||
this.transitionComplete();
|
||||
};
|
||||
SceneTransition.prototype.transitionComplete = function () {
|
||||
SceneManager.sceneTransition = null;
|
||||
if (this.previousSceneRender) {
|
||||
this.previousSceneRender.dispose();
|
||||
this.previousSceneRender = null;
|
||||
}
|
||||
if (this.onTransitionCompleted) {
|
||||
this.onTransitionCompleted();
|
||||
}
|
||||
};
|
||||
SceneTransition.prototype.loadScene = function () {
|
||||
var _this = this;
|
||||
return new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
|
||||
var _a;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0:
|
||||
if (this.onScreenObscured)
|
||||
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];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
SceneTransition.prototype.loadNextScene = function () {
|
||||
if (this.onScreenObscured)
|
||||
this.onScreenObscured();
|
||||
if (!this.loadsNewScene) {
|
||||
this.isNewSceneLoaded = true;
|
||||
}
|
||||
SceneManager.scene = this.sceneLoadAction();
|
||||
this.isNewSceneLoaded = true;
|
||||
};
|
||||
return SceneTransition;
|
||||
}());
|
||||
var FadeTransition = (function (_super) {
|
||||
__extends(FadeTransition, _super);
|
||||
function FadeTransition(sceneLoadAction) {
|
||||
var _this = _super.call(this, sceneLoadAction, true) || this;
|
||||
var _this = _super.call(this, sceneLoadAction) || this;
|
||||
_this.fadeToColor = 0x000000;
|
||||
_this.fadeOutDuration = 0.4;
|
||||
_this._color = 0xFFFFFF;
|
||||
_this._toColor = 0xFFFFFF;
|
||||
_this._destinationRect = new Rectangle(0, 0, _this.previousSceneRender.textureWidth, _this.previousSceneRender.textureHeight);
|
||||
_this.fadeEaseType = egret.Ease.quadInOut;
|
||||
_this.delayBeforeFadeInDuration = 0.1;
|
||||
_this._alpha = 0;
|
||||
_this._mask = new egret.Shape();
|
||||
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;
|
||||
}(SceneTransition));
|
||||
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
Reference in New Issue
Block a user