新增scene.optimizeCost参数 用于优化cost过高情况
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
module es {
|
||||
import Bitmap = egret.Bitmap;
|
||||
|
||||
/** 场景 */
|
||||
export class Scene extends egret.DisplayObjectContainer {
|
||||
/**
|
||||
@@ -33,7 +35,14 @@ module es {
|
||||
public _renderers: Renderer[] = [];
|
||||
public readonly _postProcessors: PostProcessor[] = [];
|
||||
public _didSceneBegin;
|
||||
/**
|
||||
* 动态合批
|
||||
*/
|
||||
public dynamicBatch: boolean = false;
|
||||
/**
|
||||
* 极致优化cost 会失去所有的事件(触摸、点击) 慎重开启
|
||||
*/
|
||||
public optimizeCost: boolean = false;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
@@ -203,6 +212,7 @@ module es {
|
||||
this.addChild(component.displayObject);
|
||||
this.addChild(component.debugDisplayObject);
|
||||
batching = false;
|
||||
if (this.optimizeCost && displayContainer) this.optimizeCombine(displayContainer);
|
||||
displayContainer = null;
|
||||
} else if (component instanceof RenderableComponent) {
|
||||
// 静态
|
||||
@@ -210,6 +220,8 @@ module es {
|
||||
batching = true;
|
||||
displayContainer = new egret.DisplayObjectContainer();
|
||||
displayContainer.cacheAsBitmap = true;
|
||||
displayContainer.touchEnabled = false;
|
||||
displayContainer.touchChildren = false;
|
||||
this.addChild(displayContainer);
|
||||
}
|
||||
|
||||
@@ -217,6 +229,18 @@ module es {
|
||||
displayContainer.addChild(component.debugDisplayObject);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.optimizeCost && displayContainer) this.optimizeCombine(displayContainer);
|
||||
}
|
||||
|
||||
private optimizeCombine(container: egret.DisplayObjectContainer){
|
||||
let renderTexture = new egret.RenderTexture();
|
||||
renderTexture.drawToTexture(container, new Rectangle(0, 0, container.width, container.height));
|
||||
let parent = container.parent;
|
||||
let index = this.getChildIndex(container);
|
||||
parent.addChildAt(new Bitmap(renderTexture), index);
|
||||
parent.removeChild(container);
|
||||
container.removeChildren();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user