新增相机震动、场景组件
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# egret-framework
|
Cegret-framework
|
||||||
|
|
||||||
|
|
||||||
[](https://lgtm.com/projects/g/esengine/egret-framework/context:javascript)
|
[](https://lgtm.com/projects/g/esengine/egret-framework/context:javascript)
|
||||||
@@ -11,26 +11,59 @@
|
|||||||
- [x] 组件列表
|
- [x] 组件列表
|
||||||
- [x] 碰撞组件
|
- [x] 碰撞组件
|
||||||
- [x] 移动组件
|
- [x] 移动组件
|
||||||
- [ ] 刚体组件
|
- [x] 滚动精灵组件
|
||||||
- [ ] 点光源/灯光组件
|
- [x] 平铺精灵组件
|
||||||
- [ ] 阴影组件
|
- [x] 序列帧动画组件
|
||||||
- [ ] 轨迹组件
|
- [x] 相机震动组件
|
||||||
- [ ] 滚动组件
|
- [x] 相机组件
|
||||||
- [ ] 网格弹簧组件
|
- [x] 组件池
|
||||||
- [ ] 相机震动组件
|
- [x] 基础碰撞组件(矩形、圆形、多边形碰撞)
|
||||||
- [ ] 霓虹灯组件
|
- [x] 场景组件
|
||||||
- [x] 跟随相机组件
|
|
||||||
- [x] 系统列表
|
- [x] 系统列表
|
||||||
- [x] 被动系统
|
- [x] 被动系统
|
||||||
- [x] 协调系统
|
- [x] 协调系统
|
||||||
|
- [x] 实体系统
|
||||||
|
- [x] 实体解析系统
|
||||||
|
- [x] 扩展库
|
||||||
|
- [x] object扩展
|
||||||
|
- [x] string扩展
|
||||||
|
- [x] texture扩展
|
||||||
|
- [x] time扩展
|
||||||
|
- [x] array扩展(Extension)
|
||||||
|
- [x] base64扩展
|
||||||
|
- [x] Stopwatch计数器
|
||||||
|
- [x] Input输入帮助
|
||||||
|
- [x] Keyboard键盘帮助
|
||||||
|
- [x] List池对象
|
||||||
|
- [x] Lock锁帮助
|
||||||
|
- [x] Emitter事件发射器
|
||||||
|
- [x] Random随机类帮助
|
||||||
|
- [x] Rectangle矩形帮助类
|
||||||
|
- [x] Vector2向量帮助类
|
||||||
|
- [x] Content资源管理器
|
||||||
|
- [x] 全局管理器
|
||||||
|
- [x] 向量集Bitset
|
||||||
|
- [x] 图形帮助
|
||||||
|
- [x] 场景过渡
|
||||||
|
- [x] 后处理器
|
||||||
|
- [x] 场景渲染器
|
||||||
|
- [x] 特效组
|
||||||
- [x] A*寻路(AStar)
|
- [x] A*寻路(AStar)
|
||||||
- [x] 常用碰撞检测
|
- [x] 常用碰撞检测
|
||||||
- [x] 数学库
|
- [x] 数学库
|
||||||
- [x] 简易矩阵类
|
- [x] 矩形类(Rectangle)
|
||||||
- [x] 简易2d 向量类
|
- [x] 简易2D矩阵类(Matrix2D)
|
||||||
- [x] 掩码实用类
|
- [x] 简易2d 向量类(Vector2)
|
||||||
- [x] 贝塞尔曲线
|
- [x] 数学扩展库(MathHelper)
|
||||||
- [x] 快速随机数类
|
- [x] 掩码实用类(Flags)
|
||||||
|
- [x] 贝塞尔曲线(Bezier)
|
||||||
|
- [x] 物理系统(简易)
|
||||||
|
- [x] Collision碰撞检测
|
||||||
|
- [x] ColliderTrigger帮助
|
||||||
|
- [x] Ray2D射线检测
|
||||||
|
- [x] ShapeCollision 多种形状检测
|
||||||
|
- [x] RealtimeCollisions 实时碰撞检测
|
||||||
|
- [x] SpatialHash 网格检测
|
||||||
- [x] BreadthFirst 寻路算法
|
- [x] BreadthFirst 寻路算法
|
||||||
- [x] Dijkstra 寻路算法
|
- [x] Dijkstra 寻路算法
|
||||||
- [x] 事件处理器
|
- [x] 事件处理器
|
||||||
|
|||||||
Vendored
+27
-6
@@ -348,6 +348,7 @@ declare module es {
|
|||||||
readonly entities: EntityList;
|
readonly entities: EntityList;
|
||||||
readonly renderableComponents: RenderableComponentList;
|
readonly renderableComponents: RenderableComponentList;
|
||||||
readonly entityProcessors: EntityProcessorList;
|
readonly entityProcessors: EntityProcessorList;
|
||||||
|
readonly _sceneComponents: SceneComponent[];
|
||||||
_renderers: Renderer[];
|
_renderers: Renderer[];
|
||||||
readonly _postProcessors: PostProcessor[];
|
readonly _postProcessors: PostProcessor[];
|
||||||
_didSceneBegin: any;
|
_didSceneBegin: any;
|
||||||
@@ -363,6 +364,10 @@ declare module es {
|
|||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
postRender(): void;
|
postRender(): void;
|
||||||
|
addSceneComponent<T extends SceneComponent>(component: T): T;
|
||||||
|
getSceneComponent<T extends SceneComponent>(type: any): T;
|
||||||
|
getOrCreateSceneComponent<T extends SceneComponent>(type: any): T;
|
||||||
|
removeSceneComponent(component: SceneComponent): void;
|
||||||
addRenderer<T extends Renderer>(renderer: T): T;
|
addRenderer<T extends Renderer>(renderer: T): T;
|
||||||
getRenderer<T extends Renderer>(type: any): T;
|
getRenderer<T extends Renderer>(type: any): T;
|
||||||
removeRenderer(renderer: Renderer): void;
|
removeRenderer(renderer: Renderer): void;
|
||||||
@@ -521,6 +526,16 @@ declare module es {
|
|||||||
protected updateMatrixes(): void;
|
protected updateMatrixes(): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
class CameraShake extends Component {
|
||||||
|
_shakeDirection: Vector2;
|
||||||
|
_shakeOffset: Vector2;
|
||||||
|
_shakeIntensity: number;
|
||||||
|
_shakeDegredation: number;
|
||||||
|
shake(shakeIntensify?: number, shakeDegredation?: number, shakeDirection?: Vector2): void;
|
||||||
|
update(): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class ComponentPool<T extends PooledComponent> {
|
class ComponentPool<T extends PooledComponent> {
|
||||||
private _cache;
|
private _cache;
|
||||||
@@ -568,12 +583,18 @@ declare module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class Mesh extends RenderableComponent {
|
class SceneComponent {
|
||||||
private _mesh;
|
scene: Scene;
|
||||||
constructor();
|
enabled: boolean;
|
||||||
setTexture(texture: egret.Texture): Mesh;
|
updateOrder: number;
|
||||||
reset(): void;
|
_enabled: boolean;
|
||||||
render(camera: es.Camera): void;
|
onEnabled(): void;
|
||||||
|
onDisabled(): void;
|
||||||
|
onRemovedFromScene(): void;
|
||||||
|
update(): void;
|
||||||
|
setEnabled(isEnabled: boolean): SceneComponent;
|
||||||
|
setUpdateOrder(updateOrder: number): this;
|
||||||
|
compareTo(other: SceneComponent): number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
|
|||||||
@@ -1615,6 +1615,7 @@ var es;
|
|||||||
function Scene() {
|
function Scene() {
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
_this.enablePostProcessing = true;
|
_this.enablePostProcessing = true;
|
||||||
|
_this._sceneComponents = [];
|
||||||
_this._renderers = [];
|
_this._renderers = [];
|
||||||
_this._postProcessors = [];
|
_this._postProcessors = [];
|
||||||
_this.entities = new es.EntityList(_this);
|
_this.entities = new es.EntityList(_this);
|
||||||
@@ -1676,6 +1677,10 @@ var es;
|
|||||||
}
|
}
|
||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
this.removeChildren();
|
this.removeChildren();
|
||||||
|
for (var i = 0; i < this._sceneComponents.length; i++) {
|
||||||
|
this._sceneComponents[i].onRemovedFromScene();
|
||||||
|
}
|
||||||
|
this._sceneComponents.length = 0;
|
||||||
this.camera = null;
|
this.camera = null;
|
||||||
this.content.dispose();
|
this.content.dispose();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
@@ -1686,6 +1691,10 @@ var es;
|
|||||||
};
|
};
|
||||||
Scene.prototype.update = function () {
|
Scene.prototype.update = function () {
|
||||||
this.entities.updateLists();
|
this.entities.updateLists();
|
||||||
|
for (var i = this._sceneComponents.length - 1; i >= 0; i--) {
|
||||||
|
if (this._sceneComponents[i].enabled)
|
||||||
|
this._sceneComponents[i].update();
|
||||||
|
}
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.update();
|
this.entityProcessors.update();
|
||||||
this.entities.update();
|
this.entities.update();
|
||||||
@@ -1711,6 +1720,35 @@ var es;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Scene.prototype.addSceneComponent = function (component) {
|
||||||
|
component.scene = this;
|
||||||
|
component.onEnabled();
|
||||||
|
this._sceneComponents.push(component);
|
||||||
|
this._sceneComponents.sort(component.compareTo);
|
||||||
|
return component;
|
||||||
|
};
|
||||||
|
Scene.prototype.getSceneComponent = function (type) {
|
||||||
|
for (var i = 0; i < this._sceneComponents.length; i++) {
|
||||||
|
var component = this._sceneComponents[i];
|
||||||
|
if (component instanceof type)
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
Scene.prototype.getOrCreateSceneComponent = function (type) {
|
||||||
|
var comp = this.getSceneComponent(type);
|
||||||
|
if (comp == null)
|
||||||
|
comp = this.addSceneComponent(new type());
|
||||||
|
return comp;
|
||||||
|
};
|
||||||
|
Scene.prototype.removeSceneComponent = function (component) {
|
||||||
|
if (!this._sceneComponents.contains(component)) {
|
||||||
|
console.warn("SceneComponent" + component + "\u4E0D\u5728SceneComponents\u5217\u8868\u4E2D!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._sceneComponents.remove(component);
|
||||||
|
component.onRemovedFromScene();
|
||||||
|
};
|
||||||
Scene.prototype.addRenderer = function (renderer) {
|
Scene.prototype.addRenderer = function (renderer) {
|
||||||
this._renderers.push(renderer);
|
this._renderers.push(renderer);
|
||||||
this._renderers.sort();
|
this._renderers.sort();
|
||||||
@@ -2494,6 +2532,55 @@ var es;
|
|||||||
es.Camera = Camera;
|
es.Camera = Camera;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var CameraShake = (function (_super) {
|
||||||
|
__extends(CameraShake, _super);
|
||||||
|
function CameraShake() {
|
||||||
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
_this._shakeDirection = es.Vector2.zero;
|
||||||
|
_this._shakeOffset = es.Vector2.zero;
|
||||||
|
_this._shakeIntensity = 0;
|
||||||
|
_this._shakeDegredation = 0.95;
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
CameraShake.prototype.shake = function (shakeIntensify, shakeDegredation, shakeDirection) {
|
||||||
|
if (shakeIntensify === void 0) { shakeIntensify = 15; }
|
||||||
|
if (shakeDegredation === void 0) { shakeDegredation = 0.9; }
|
||||||
|
if (shakeDirection === void 0) { shakeDirection = es.Vector2.zero; }
|
||||||
|
this.enabled = true;
|
||||||
|
if (this._shakeIntensity < shakeIntensify) {
|
||||||
|
this._shakeDirection = shakeDirection;
|
||||||
|
this._shakeIntensity = shakeIntensify;
|
||||||
|
if (shakeDegredation < 0 || shakeDegredation >= 1) {
|
||||||
|
shakeDegredation = 0.95;
|
||||||
|
}
|
||||||
|
this._shakeDegredation = shakeDegredation;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
CameraShake.prototype.update = function () {
|
||||||
|
if (Math.abs(this._shakeIntensity) > 0) {
|
||||||
|
this._shakeOffset = this._shakeDirection;
|
||||||
|
if (this._shakeOffset.x != 0 || this._shakeOffset.y != 0) {
|
||||||
|
this._shakeOffset.normalize();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this._shakeOffset.x = this._shakeOffset.x + Math.random() - 0.5;
|
||||||
|
this._shakeOffset.y = this._shakeOffset.y + Math.random() - 0.5;
|
||||||
|
}
|
||||||
|
this._shakeOffset.multiply(new es.Vector2(this._shakeIntensity));
|
||||||
|
this._shakeIntensity *= -this._shakeDegredation;
|
||||||
|
if (Math.abs(this._shakeIntensity) <= 0.01) {
|
||||||
|
this._shakeIntensity = 0;
|
||||||
|
this.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.entity.scene.camera.position.add(this._shakeOffset);
|
||||||
|
};
|
||||||
|
return CameraShake;
|
||||||
|
}(es.Component));
|
||||||
|
es.CameraShake = CameraShake;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var ComponentPool = (function () {
|
var ComponentPool = (function () {
|
||||||
function ComponentPool(typeClass) {
|
function ComponentPool(typeClass) {
|
||||||
@@ -2662,25 +2749,52 @@ var es;
|
|||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var Mesh = (function (_super) {
|
var SceneComponent = (function () {
|
||||||
__extends(Mesh, _super);
|
function SceneComponent() {
|
||||||
function Mesh() {
|
this.updateOrder = 0;
|
||||||
var _this = _super.call(this) || this;
|
this._enabled = true;
|
||||||
_this._mesh = new egret.Mesh();
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
Mesh.prototype.setTexture = function (texture) {
|
Object.defineProperty(SceneComponent.prototype, "enabled", {
|
||||||
this._mesh.texture = texture;
|
get: function () {
|
||||||
this._mesh.$renderNode = new egret.sys.RenderNode();
|
return this._enabled;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setEnabled(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
SceneComponent.prototype.onEnabled = function () {
|
||||||
|
};
|
||||||
|
SceneComponent.prototype.onDisabled = function () {
|
||||||
|
};
|
||||||
|
SceneComponent.prototype.onRemovedFromScene = function () {
|
||||||
|
};
|
||||||
|
SceneComponent.prototype.update = function () {
|
||||||
|
};
|
||||||
|
SceneComponent.prototype.setEnabled = function (isEnabled) {
|
||||||
|
if (this._enabled != isEnabled) {
|
||||||
|
this._enabled = isEnabled;
|
||||||
|
if (this._enabled) {
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Mesh.prototype.reset = function () {
|
SceneComponent.prototype.setUpdateOrder = function (updateOrder) {
|
||||||
|
if (this.updateOrder != updateOrder) {
|
||||||
|
this.updateOrder = updateOrder;
|
||||||
|
es.Core.scene._sceneComponents.sort(this.compareTo);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
Mesh.prototype.render = function (camera) {
|
SceneComponent.prototype.compareTo = function (other) {
|
||||||
|
return this.updateOrder - other.updateOrder;
|
||||||
};
|
};
|
||||||
return Mesh;
|
return SceneComponent;
|
||||||
}(es.RenderableComponent));
|
}());
|
||||||
es.Mesh = Mesh;
|
es.SceneComponent = SceneComponent;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+27
-6
@@ -348,6 +348,7 @@ declare module es {
|
|||||||
readonly entities: EntityList;
|
readonly entities: EntityList;
|
||||||
readonly renderableComponents: RenderableComponentList;
|
readonly renderableComponents: RenderableComponentList;
|
||||||
readonly entityProcessors: EntityProcessorList;
|
readonly entityProcessors: EntityProcessorList;
|
||||||
|
readonly _sceneComponents: SceneComponent[];
|
||||||
_renderers: Renderer[];
|
_renderers: Renderer[];
|
||||||
readonly _postProcessors: PostProcessor[];
|
readonly _postProcessors: PostProcessor[];
|
||||||
_didSceneBegin: any;
|
_didSceneBegin: any;
|
||||||
@@ -363,6 +364,10 @@ declare module es {
|
|||||||
update(): void;
|
update(): void;
|
||||||
render(): void;
|
render(): void;
|
||||||
postRender(): void;
|
postRender(): void;
|
||||||
|
addSceneComponent<T extends SceneComponent>(component: T): T;
|
||||||
|
getSceneComponent<T extends SceneComponent>(type: any): T;
|
||||||
|
getOrCreateSceneComponent<T extends SceneComponent>(type: any): T;
|
||||||
|
removeSceneComponent(component: SceneComponent): void;
|
||||||
addRenderer<T extends Renderer>(renderer: T): T;
|
addRenderer<T extends Renderer>(renderer: T): T;
|
||||||
getRenderer<T extends Renderer>(type: any): T;
|
getRenderer<T extends Renderer>(type: any): T;
|
||||||
removeRenderer(renderer: Renderer): void;
|
removeRenderer(renderer: Renderer): void;
|
||||||
@@ -521,6 +526,16 @@ declare module es {
|
|||||||
protected updateMatrixes(): void;
|
protected updateMatrixes(): void;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
declare module es {
|
||||||
|
class CameraShake extends Component {
|
||||||
|
_shakeDirection: Vector2;
|
||||||
|
_shakeOffset: Vector2;
|
||||||
|
_shakeIntensity: number;
|
||||||
|
_shakeDegredation: number;
|
||||||
|
shake(shakeIntensify?: number, shakeDegredation?: number, shakeDirection?: Vector2): void;
|
||||||
|
update(): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class ComponentPool<T extends PooledComponent> {
|
class ComponentPool<T extends PooledComponent> {
|
||||||
private _cache;
|
private _cache;
|
||||||
@@ -568,12 +583,18 @@ declare module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
class Mesh extends RenderableComponent {
|
class SceneComponent {
|
||||||
private _mesh;
|
scene: Scene;
|
||||||
constructor();
|
enabled: boolean;
|
||||||
setTexture(texture: egret.Texture): Mesh;
|
updateOrder: number;
|
||||||
reset(): void;
|
_enabled: boolean;
|
||||||
render(camera: es.Camera): void;
|
onEnabled(): void;
|
||||||
|
onDisabled(): void;
|
||||||
|
onRemovedFromScene(): void;
|
||||||
|
update(): void;
|
||||||
|
setEnabled(isEnabled: boolean): SceneComponent;
|
||||||
|
setUpdateOrder(updateOrder: number): this;
|
||||||
|
compareTo(other: SceneComponent): number;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
declare module es {
|
declare module es {
|
||||||
|
|||||||
+128
-14
@@ -1615,6 +1615,7 @@ var es;
|
|||||||
function Scene() {
|
function Scene() {
|
||||||
var _this = _super.call(this) || this;
|
var _this = _super.call(this) || this;
|
||||||
_this.enablePostProcessing = true;
|
_this.enablePostProcessing = true;
|
||||||
|
_this._sceneComponents = [];
|
||||||
_this._renderers = [];
|
_this._renderers = [];
|
||||||
_this._postProcessors = [];
|
_this._postProcessors = [];
|
||||||
_this.entities = new es.EntityList(_this);
|
_this.entities = new es.EntityList(_this);
|
||||||
@@ -1676,6 +1677,10 @@ var es;
|
|||||||
}
|
}
|
||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
this.removeChildren();
|
this.removeChildren();
|
||||||
|
for (var i = 0; i < this._sceneComponents.length; i++) {
|
||||||
|
this._sceneComponents[i].onRemovedFromScene();
|
||||||
|
}
|
||||||
|
this._sceneComponents.length = 0;
|
||||||
this.camera = null;
|
this.camera = null;
|
||||||
this.content.dispose();
|
this.content.dispose();
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
@@ -1686,6 +1691,10 @@ var es;
|
|||||||
};
|
};
|
||||||
Scene.prototype.update = function () {
|
Scene.prototype.update = function () {
|
||||||
this.entities.updateLists();
|
this.entities.updateLists();
|
||||||
|
for (var i = this._sceneComponents.length - 1; i >= 0; i--) {
|
||||||
|
if (this._sceneComponents[i].enabled)
|
||||||
|
this._sceneComponents[i].update();
|
||||||
|
}
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.update();
|
this.entityProcessors.update();
|
||||||
this.entities.update();
|
this.entities.update();
|
||||||
@@ -1711,6 +1720,35 @@ var es;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Scene.prototype.addSceneComponent = function (component) {
|
||||||
|
component.scene = this;
|
||||||
|
component.onEnabled();
|
||||||
|
this._sceneComponents.push(component);
|
||||||
|
this._sceneComponents.sort(component.compareTo);
|
||||||
|
return component;
|
||||||
|
};
|
||||||
|
Scene.prototype.getSceneComponent = function (type) {
|
||||||
|
for (var i = 0; i < this._sceneComponents.length; i++) {
|
||||||
|
var component = this._sceneComponents[i];
|
||||||
|
if (component instanceof type)
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
Scene.prototype.getOrCreateSceneComponent = function (type) {
|
||||||
|
var comp = this.getSceneComponent(type);
|
||||||
|
if (comp == null)
|
||||||
|
comp = this.addSceneComponent(new type());
|
||||||
|
return comp;
|
||||||
|
};
|
||||||
|
Scene.prototype.removeSceneComponent = function (component) {
|
||||||
|
if (!this._sceneComponents.contains(component)) {
|
||||||
|
console.warn("SceneComponent" + component + "\u4E0D\u5728SceneComponents\u5217\u8868\u4E2D!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._sceneComponents.remove(component);
|
||||||
|
component.onRemovedFromScene();
|
||||||
|
};
|
||||||
Scene.prototype.addRenderer = function (renderer) {
|
Scene.prototype.addRenderer = function (renderer) {
|
||||||
this._renderers.push(renderer);
|
this._renderers.push(renderer);
|
||||||
this._renderers.sort();
|
this._renderers.sort();
|
||||||
@@ -2494,6 +2532,55 @@ var es;
|
|||||||
es.Camera = Camera;
|
es.Camera = Camera;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
|
(function (es) {
|
||||||
|
var CameraShake = (function (_super) {
|
||||||
|
__extends(CameraShake, _super);
|
||||||
|
function CameraShake() {
|
||||||
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||||
|
_this._shakeDirection = es.Vector2.zero;
|
||||||
|
_this._shakeOffset = es.Vector2.zero;
|
||||||
|
_this._shakeIntensity = 0;
|
||||||
|
_this._shakeDegredation = 0.95;
|
||||||
|
return _this;
|
||||||
|
}
|
||||||
|
CameraShake.prototype.shake = function (shakeIntensify, shakeDegredation, shakeDirection) {
|
||||||
|
if (shakeIntensify === void 0) { shakeIntensify = 15; }
|
||||||
|
if (shakeDegredation === void 0) { shakeDegredation = 0.9; }
|
||||||
|
if (shakeDirection === void 0) { shakeDirection = es.Vector2.zero; }
|
||||||
|
this.enabled = true;
|
||||||
|
if (this._shakeIntensity < shakeIntensify) {
|
||||||
|
this._shakeDirection = shakeDirection;
|
||||||
|
this._shakeIntensity = shakeIntensify;
|
||||||
|
if (shakeDegredation < 0 || shakeDegredation >= 1) {
|
||||||
|
shakeDegredation = 0.95;
|
||||||
|
}
|
||||||
|
this._shakeDegredation = shakeDegredation;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
CameraShake.prototype.update = function () {
|
||||||
|
if (Math.abs(this._shakeIntensity) > 0) {
|
||||||
|
this._shakeOffset = this._shakeDirection;
|
||||||
|
if (this._shakeOffset.x != 0 || this._shakeOffset.y != 0) {
|
||||||
|
this._shakeOffset.normalize();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this._shakeOffset.x = this._shakeOffset.x + Math.random() - 0.5;
|
||||||
|
this._shakeOffset.y = this._shakeOffset.y + Math.random() - 0.5;
|
||||||
|
}
|
||||||
|
this._shakeOffset.multiply(new es.Vector2(this._shakeIntensity));
|
||||||
|
this._shakeIntensity *= -this._shakeDegredation;
|
||||||
|
if (Math.abs(this._shakeIntensity) <= 0.01) {
|
||||||
|
this._shakeIntensity = 0;
|
||||||
|
this.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.entity.scene.camera.position.add(this._shakeOffset);
|
||||||
|
};
|
||||||
|
return CameraShake;
|
||||||
|
}(es.Component));
|
||||||
|
es.CameraShake = CameraShake;
|
||||||
|
})(es || (es = {}));
|
||||||
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var ComponentPool = (function () {
|
var ComponentPool = (function () {
|
||||||
function ComponentPool(typeClass) {
|
function ComponentPool(typeClass) {
|
||||||
@@ -2662,25 +2749,52 @@ var es;
|
|||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
var Mesh = (function (_super) {
|
var SceneComponent = (function () {
|
||||||
__extends(Mesh, _super);
|
function SceneComponent() {
|
||||||
function Mesh() {
|
this.updateOrder = 0;
|
||||||
var _this = _super.call(this) || this;
|
this._enabled = true;
|
||||||
_this._mesh = new egret.Mesh();
|
|
||||||
return _this;
|
|
||||||
}
|
}
|
||||||
Mesh.prototype.setTexture = function (texture) {
|
Object.defineProperty(SceneComponent.prototype, "enabled", {
|
||||||
this._mesh.texture = texture;
|
get: function () {
|
||||||
this._mesh.$renderNode = new egret.sys.RenderNode();
|
return this._enabled;
|
||||||
|
},
|
||||||
|
set: function (value) {
|
||||||
|
this.setEnabled(value);
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
SceneComponent.prototype.onEnabled = function () {
|
||||||
|
};
|
||||||
|
SceneComponent.prototype.onDisabled = function () {
|
||||||
|
};
|
||||||
|
SceneComponent.prototype.onRemovedFromScene = function () {
|
||||||
|
};
|
||||||
|
SceneComponent.prototype.update = function () {
|
||||||
|
};
|
||||||
|
SceneComponent.prototype.setEnabled = function (isEnabled) {
|
||||||
|
if (this._enabled != isEnabled) {
|
||||||
|
this._enabled = isEnabled;
|
||||||
|
if (this._enabled) {
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
}
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
Mesh.prototype.reset = function () {
|
SceneComponent.prototype.setUpdateOrder = function (updateOrder) {
|
||||||
|
if (this.updateOrder != updateOrder) {
|
||||||
|
this.updateOrder = updateOrder;
|
||||||
|
es.Core.scene._sceneComponents.sort(this.compareTo);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
Mesh.prototype.render = function (camera) {
|
SceneComponent.prototype.compareTo = function (other) {
|
||||||
|
return this.updateOrder - other.updateOrder;
|
||||||
};
|
};
|
||||||
return Mesh;
|
return SceneComponent;
|
||||||
}(es.RenderableComponent));
|
}());
|
||||||
es.Mesh = Mesh;
|
es.SceneComponent = SceneComponent;
|
||||||
})(es || (es = {}));
|
})(es || (es = {}));
|
||||||
var es;
|
var es;
|
||||||
(function (es) {
|
(function (es) {
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,50 @@
|
|||||||
|
module es {
|
||||||
|
export class CameraShake extends Component {
|
||||||
|
public _shakeDirection: Vector2 = Vector2.zero;
|
||||||
|
public _shakeOffset: Vector2 = Vector2.zero;
|
||||||
|
public _shakeIntensity = 0;
|
||||||
|
public _shakeDegredation = 0.95;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果震动已经在运行,只有震动强度>当前shakeIntensity, 将覆盖当前值
|
||||||
|
* 如果shake当前不是活动的,它将被启动。
|
||||||
|
* @param shakeIntensify 震动强度
|
||||||
|
* @param shakeDegredation 较高的值会导致更快的停止震动
|
||||||
|
* @param shakeDirection 0只会导致x/y轴上的振动。任何其他的值将导致通过在抖动方向*强度是相机移动偏移
|
||||||
|
*/
|
||||||
|
public shake(shakeIntensify = 15, shakeDegredation = 0.9, shakeDirection = Vector2.zero){
|
||||||
|
this.enabled = true;
|
||||||
|
if (this._shakeIntensity < shakeIntensify) {
|
||||||
|
this._shakeDirection = shakeDirection;
|
||||||
|
this._shakeIntensity = shakeIntensify;
|
||||||
|
if (shakeDegredation < 0 || shakeDegredation >= 1){
|
||||||
|
shakeDegredation = 0.95;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._shakeDegredation = shakeDegredation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public update() {
|
||||||
|
if (Math.abs(this._shakeIntensity) > 0){
|
||||||
|
this._shakeOffset = this._shakeDirection;
|
||||||
|
if (this._shakeOffset.x != 0 || this._shakeOffset.y != 0){
|
||||||
|
this._shakeOffset.normalize();
|
||||||
|
}else{
|
||||||
|
this._shakeOffset.x = this._shakeOffset.x + Math.random() - 0.5;
|
||||||
|
this._shakeOffset.y = this._shakeOffset.y + Math.random() - 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: 这需要乘相机变焦
|
||||||
|
this._shakeOffset.multiply(new Vector2(this._shakeIntensity));
|
||||||
|
this._shakeIntensity *= -this._shakeDegredation;
|
||||||
|
if (Math.abs(this._shakeIntensity) <= 0.01){
|
||||||
|
this._shakeIntensity = 0;
|
||||||
|
this.enabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.entity.scene.camera.position.add(this._shakeOffset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
///<reference path="./RenderableComponent.ts" />
|
|
||||||
module es {
|
|
||||||
export class Mesh extends RenderableComponent {
|
|
||||||
private _mesh: egret.Mesh;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this._mesh = new egret.Mesh();
|
|
||||||
}
|
|
||||||
|
|
||||||
public setTexture(texture: egret.Texture): Mesh {
|
|
||||||
this._mesh.texture = texture;
|
|
||||||
this._mesh.$renderNode = new egret.sys.RenderNode();
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public reset() {
|
|
||||||
}
|
|
||||||
|
|
||||||
render(camera: es.Camera) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
module es {
|
||||||
|
export class SceneComponent {
|
||||||
|
/**
|
||||||
|
* 这个场景组件被附加到的场景
|
||||||
|
*/
|
||||||
|
public scene: Scene;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果启用了SceneComponent,则为true。状态的改变会导致调用onEnabled/onDisable。
|
||||||
|
*/
|
||||||
|
public get enabled(){
|
||||||
|
return this._enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果启用了SceneComponent,则为true。状态的改变会导致调用onEnabled/onDisable。
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public set enabled(value: boolean){
|
||||||
|
this.setEnabled(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新此场景中SceneComponents的顺序
|
||||||
|
*/
|
||||||
|
public updateOrder: number = 0;
|
||||||
|
|
||||||
|
public _enabled: boolean = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在启用此SceneComponent时调用
|
||||||
|
*/
|
||||||
|
public onEnabled(){
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当禁用此SceneComponent时调用
|
||||||
|
*/
|
||||||
|
public onDisabled(){
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当该SceneComponent从场景中移除时调用
|
||||||
|
*/
|
||||||
|
public onRemovedFromScene(){
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在实体更新之前每一帧调用
|
||||||
|
*/
|
||||||
|
public update(){
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用/禁用这个SceneComponent
|
||||||
|
* @param isEnabled
|
||||||
|
*/
|
||||||
|
public setEnabled(isEnabled: boolean): SceneComponent{
|
||||||
|
if (this._enabled != isEnabled){
|
||||||
|
this._enabled = isEnabled;
|
||||||
|
|
||||||
|
if (this._enabled){
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置SceneComponent的updateOrder并触发某种SceneComponent
|
||||||
|
* @param updateOrder
|
||||||
|
*/
|
||||||
|
public setUpdateOrder(updateOrder: number){
|
||||||
|
if (this.updateOrder != updateOrder){
|
||||||
|
this.updateOrder = updateOrder;
|
||||||
|
Core.scene._sceneComponents.sort(this.compareTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public compareTo(other: SceneComponent): number{
|
||||||
|
return this.updateOrder - other.updateOrder;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ module es {
|
|||||||
*/
|
*/
|
||||||
public readonly entityProcessors: EntityProcessorList;
|
public readonly entityProcessors: EntityProcessorList;
|
||||||
|
|
||||||
|
public readonly _sceneComponents: SceneComponent[] = [];
|
||||||
public _renderers: Renderer[] = [];
|
public _renderers: Renderer[] = [];
|
||||||
public readonly _postProcessors: PostProcessor[] = [];
|
public readonly _postProcessors: PostProcessor[] = [];
|
||||||
public _didSceneBegin;
|
public _didSceneBegin;
|
||||||
@@ -120,6 +121,11 @@ module es {
|
|||||||
this.entities.removeAllEntities();
|
this.entities.removeAllEntities();
|
||||||
this.removeChildren();
|
this.removeChildren();
|
||||||
|
|
||||||
|
for (let i = 0; i < this._sceneComponents.length; i ++){
|
||||||
|
this._sceneComponents[i].onRemovedFromScene();
|
||||||
|
}
|
||||||
|
this._sceneComponents.length = 0;
|
||||||
|
|
||||||
this.camera = null;
|
this.camera = null;
|
||||||
this.content.dispose();
|
this.content.dispose();
|
||||||
|
|
||||||
@@ -136,6 +142,11 @@ module es {
|
|||||||
// 更新我们的列表,以防它们有任何变化
|
// 更新我们的列表,以防它们有任何变化
|
||||||
this.entities.updateLists();
|
this.entities.updateLists();
|
||||||
|
|
||||||
|
for (let i = this._sceneComponents.length - 1; i >= 0; i --){
|
||||||
|
if (this._sceneComponents[i].enabled)
|
||||||
|
this._sceneComponents[i].update();
|
||||||
|
}
|
||||||
|
|
||||||
// 更新我们的实体解析器
|
// 更新我们的实体解析器
|
||||||
if (this.entityProcessors)
|
if (this.entityProcessors)
|
||||||
this.entityProcessors.update();
|
this.entityProcessors.update();
|
||||||
@@ -175,6 +186,58 @@ module es {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向组件列表添加并返回SceneComponent
|
||||||
|
* @param component
|
||||||
|
*/
|
||||||
|
public addSceneComponent<T extends SceneComponent>(component: T): T {
|
||||||
|
component.scene = this;
|
||||||
|
component.onEnabled();
|
||||||
|
this._sceneComponents.push(component);
|
||||||
|
this._sceneComponents.sort(component.compareTo);
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取类型为T的第一个SceneComponent并返回它。如果没有找到组件,则返回null。
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
public getSceneComponent<T extends SceneComponent>(type){
|
||||||
|
for (let i = 0; i < this._sceneComponents.length; i ++){
|
||||||
|
let component = this._sceneComponents[i];
|
||||||
|
if (component instanceof type)
|
||||||
|
return component as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取类型为T的第一个SceneComponent并返回它。如果没有找到SceneComponent,则将创建SceneComponent。
|
||||||
|
* @param type
|
||||||
|
*/
|
||||||
|
public getOrCreateSceneComponent<T extends SceneComponent>(type){
|
||||||
|
let comp = this.getSceneComponent<T>(type);
|
||||||
|
if (comp == null)
|
||||||
|
comp = this.addSceneComponent<T>(new type());
|
||||||
|
|
||||||
|
return comp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从SceneComponents列表中删除一个SceneComponent
|
||||||
|
* @param component
|
||||||
|
*/
|
||||||
|
public removeSceneComponent(component: SceneComponent){
|
||||||
|
if (!this._sceneComponents.contains(component)){
|
||||||
|
console.warn(`SceneComponent${component}不在SceneComponents列表中!`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this._sceneComponents.remove(component);
|
||||||
|
component.onRemovedFromScene();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为场景添加一个渲染器
|
* 为场景添加一个渲染器
|
||||||
* @param renderer
|
* @param renderer
|
||||||
|
|||||||
Reference in New Issue
Block a user