update
This commit is contained in:
@@ -4,32 +4,21 @@ module es {
|
||||
* 非常重要!子类必须覆盖width/height或bounds! 子类必须覆盖width/height或bounds!
|
||||
*/
|
||||
export abstract class RenderableComponent extends Component implements IRenderable, IComparer<RenderableComponent> {
|
||||
public static renderIdGenerator: number = 0;
|
||||
/**
|
||||
* 不重写bounds属性的子类必须实现这个!RenderableComponent的宽度。
|
||||
*/
|
||||
public get width() {
|
||||
return this.bounds.width;
|
||||
}
|
||||
public abstract get width();
|
||||
|
||||
/**
|
||||
* 不重写bounds属性的子类必须实现这个!
|
||||
*/
|
||||
public get height() {
|
||||
return this.bounds.height;
|
||||
}
|
||||
public abstract get height();
|
||||
|
||||
/**
|
||||
* 包裹此对象的AABB。用来进行相机筛选。
|
||||
*/
|
||||
public get bounds(): Rectangle {
|
||||
if (this._areBoundsDirty) {
|
||||
this._bounds.calculateBounds(this.entity.transform.position, this._localOffset, Vector2.zero,
|
||||
this.entity.transform.scale, this.entity.transform.rotation, this.width, this.height);
|
||||
this._areBoundsDirty = false;
|
||||
}
|
||||
|
||||
return this._bounds;
|
||||
}
|
||||
public abstract get bounds();
|
||||
|
||||
/**
|
||||
* 标准的Batcher图层深度,0为前面,1为后面。
|
||||
@@ -53,6 +42,11 @@ module es {
|
||||
this.setRenderLayer(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染时传递给批处理程序的颜色
|
||||
*/
|
||||
public color: number = 0xffffff;
|
||||
|
||||
/**
|
||||
* 由渲染器使用,用于指定该精灵的渲染方式
|
||||
*/
|
||||
@@ -84,12 +78,16 @@ module es {
|
||||
}
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
public debugRenderEnabled: boolean = true;
|
||||
|
||||
protected _localOffset: Vector2;
|
||||
protected _localOffset: Vector2 = Vector2.zero;
|
||||
protected _layerDepth: number;
|
||||
protected _renderLayer: number;
|
||||
protected _bounds: Rectangle;
|
||||
protected _bounds: Rectangle = Rectangle.empty;
|
||||
protected _isVisble: boolean;
|
||||
|
||||
protected _areBoundsDirty: boolean = true;
|
||||
|
||||
@@ -24,5 +24,6 @@ module es {
|
||||
resolutionOffset,
|
||||
createRenderTarget,
|
||||
createCamera,
|
||||
rendererSizeChanged,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,9 @@ module es {
|
||||
public readonly _sceneComponents: SceneComponent[] = [];
|
||||
public _renderers: IRenderer[] = [];
|
||||
public readonly _afterPostProcessorRenderers: IRenderer[] = [];
|
||||
public _didSceneBegin: boolean;
|
||||
private _didSceneBegin: boolean;
|
||||
|
||||
private currentRenderId: Ref<number> = new Ref(null);
|
||||
|
||||
/**
|
||||
* 设置新场景将使用的默认设计尺寸和分辨率策略,水平/垂直Bleed仅与BestFit相关
|
||||
@@ -369,8 +371,8 @@ module es {
|
||||
Framework.emitter.emit(CoreEvents.setRenderTarget, finalRenderTarget);
|
||||
Framework.emitter.emit(CoreEvents.clearGraphics);
|
||||
|
||||
Framework.batcher.begin(null);
|
||||
Framework.batcher.draw(currentRenderTarget,
|
||||
Framework.batcher.begin(this.currentRenderId, null);
|
||||
Framework.batcher.draw(currentRenderTarget.value,
|
||||
new Vector2(this._finalRenderDestinationRect.x, this._finalRenderDestinationRect.y),
|
||||
0xffffff,
|
||||
0,
|
||||
@@ -451,6 +453,9 @@ module es {
|
||||
|
||||
renderer.onAddedToScene(this);
|
||||
|
||||
if (this._didSceneBegin)
|
||||
Framework.emitter.emit(CoreEvents.rendererSizeChanged, this._sceneRenderTarget.value);
|
||||
|
||||
return renderer;
|
||||
}
|
||||
|
||||
@@ -477,13 +482,15 @@ module es {
|
||||
* @param renderer
|
||||
*/
|
||||
public removeRenderer(renderer: IRenderer) {
|
||||
Insist.isTrue(new linq.List(this._renderers).contains(renderer) ||
|
||||
new linq.List(this._afterPostProcessorRenderers).contains(renderer));
|
||||
let afterProcessLinqList = new linq.List(this._afterPostProcessorRenderers);
|
||||
let rendererLinqList = new linq.List(this._renderers);
|
||||
Insist.isTrue(rendererLinqList.contains(renderer) ||
|
||||
afterProcessLinqList.contains(renderer));
|
||||
|
||||
if (renderer.wantsToRenderAfterPostProcessors)
|
||||
new linq.List(this._afterPostProcessorRenderers).remove(renderer);
|
||||
afterProcessLinqList.remove(renderer);
|
||||
else
|
||||
new linq.List(this._renderers).remove(renderer);
|
||||
rendererLinqList.remove(renderer);
|
||||
|
||||
renderer.unload();
|
||||
}
|
||||
|
||||
@@ -82,6 +82,9 @@ module es {
|
||||
for (let component of this._components) {
|
||||
if (!component) continue;
|
||||
|
||||
if (component instanceof RenderableComponent)
|
||||
new linq.List(this._entity.scene.renderableComponents.buffer).remove(component);
|
||||
|
||||
// 处理IUpdatable
|
||||
if (isIUpdatable(component))
|
||||
new linq.List(this._updatableComponents).remove(component);
|
||||
@@ -93,6 +96,9 @@ module es {
|
||||
|
||||
public registerAllComponents() {
|
||||
for (let component of this._components) {
|
||||
if (component instanceof RenderableComponent)
|
||||
this._entity.scene.renderableComponents.buffer.push(component);
|
||||
|
||||
if (isIUpdatable(component))
|
||||
this._updatableComponents.push(component);
|
||||
|
||||
@@ -118,6 +124,9 @@ module es {
|
||||
for (let i = 0, count = this._componentsToAdd.length; i < count; i++) {
|
||||
let component = this._componentsToAdd[i];
|
||||
|
||||
if (component instanceof RenderableComponent)
|
||||
this._entity.scene.renderableComponents.buffer.push(component);
|
||||
|
||||
if (isIUpdatable(component))
|
||||
this._updatableComponents.push(component);
|
||||
|
||||
@@ -153,7 +162,8 @@ module es {
|
||||
}
|
||||
|
||||
public handleRemove(component: Component) {
|
||||
if (!component) return;
|
||||
if (component instanceof RenderableComponent)
|
||||
new linq.List(this._entity.scene.renderableComponents.buffer).remove(component);
|
||||
|
||||
if (isIUpdatable(component))
|
||||
new linq.List(this._updatableComponents).remove(component);
|
||||
|
||||
@@ -19,6 +19,10 @@ module es {
|
||||
return this._components.length;
|
||||
}
|
||||
|
||||
public get buffer(){
|
||||
return this._components;
|
||||
}
|
||||
|
||||
public get(index: number): IRenderable {
|
||||
return this._components[index];
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ module es {
|
||||
*/
|
||||
shouldRoundDestinations: boolean;
|
||||
disposed();
|
||||
begin(effect, transformationMatrix?: Matrix, disableBatching?: boolean);
|
||||
begin(id: Ref<number>, effect, transformationMatrix?: Matrix, disableBatching?: boolean);
|
||||
end();
|
||||
prepRenderState();
|
||||
/**
|
||||
@@ -19,10 +19,7 @@ module es {
|
||||
drawHollowRect(rect: Rectangle, color: number, thickness?: number);
|
||||
drawHollowBounds(x: number, y: number, width: number, height: number, color: number, thickness: number);
|
||||
drawLine(start: Vector2, end: Vector2, color: number, thickness);
|
||||
drawLineAngle(start: Vector2, radians: number, length: number, color: number, thickness: number);
|
||||
draw(texture, position: Vector2, color?: number, rotation?: number, origin?: Vector2, scale?: Vector2, effects?);
|
||||
flushBatch();
|
||||
drawPrimitives(texture, baseSprite: number, batchSize: number);
|
||||
drawPixel(position: Vector2, color: number, size?: number);
|
||||
drawPolygon(position: Vector2, points: Vector2[], color: number, closePoly?: boolean, thickness?: number);
|
||||
drawCircle(position: Vector2, radius: number, color: number, thickness?: number, resolution?: number);
|
||||
|
||||
Reference in New Issue
Block a user