Commit b74d8660 authored by 邱旭's avatar 邱旭

合并2.0.70一点东西

parent 36e2ca2a
import { createCanvas } from "./utils";
import { Sprite } from "./display";
import { Texture } from "./texture";
export class FpsPanel extends Sprite {
private context: CanvasRenderingContext2D;
private bgColor: string = '#002002';
private textColor: string = '#0ff0ff';
private PR: number = 3;
private WIDTH = 80 * this.PR;
private HEIGHT = 48 * this.PR;
private TEXT_X = 3 * this.PR;
private TEXT_Y = 2 * this.PR;
private GRAPH_X = 3 * this.PR;
private GRAPH_Y = 15 * this.PR;
private GRAPH_WIDTH = 74 * this.PR;
private GRAPH_HEIGHT = 30 * this.PR;
private GRAPH_SIZE = 74;
private maxValue = 120;
private min = Infinity;
private max = 0;
private items = [];
/**
* 帧率面板
* 后续可以加入每次drawCall,总绘制对象等等
*/
constructor() {
super()
//离屏canvas
var canvas = createCanvas();
canvas.width = this.WIDTH;
canvas.height = this.HEIGHT;
this.texture = Texture.fromCanvas(canvas)
this.context = canvas.getContext("2d");
this.context.font = 'bold ' + (9 * this.PR) + 'px Helvetica,Arial,sans-serif';
this.context.textBaseline = 'top';
this.updateText("FPS");
}
private lastTime: number = Date.now();
private frames: number = 0;
reset() {
this.lastTime = Date.now();
this.min = Infinity;
this.max = 0;
this.items.length = 0;
this.frames = 0;
}
update() {
this.frames++;
var time = Date.now();
//每秒跑一次
if (time >= this.lastTime + 1000) {
var value = (this.frames * 1000) / (time - this.lastTime);
this.updatePanel(value)
this.lastTime = time;
this.frames = 0;
}
super.update();
}
private updatePanel(value: number) {
const { items, GRAPH_SIZE, context, GRAPH_X, textColor, GRAPH_Y, PR, GRAPH_HEIGHT, bgColor, maxValue } = this
items.push(value);
while (items.length > GRAPH_SIZE) {
items.shift();
}
this.min = Math.min(this.min, value);
this.max = Math.max(this.max, value);
this.updateText(Math.round(value) + ' FPS (' + Math.round(this.min) + '-' + Math.round(this.max) + ')');
for (var i = 0; i < items.length; i++) {
var startPos = GRAPH_X + (i + GRAPH_SIZE - items.length) * PR;
context.fillStyle = textColor;
context.globalAlpha = 1;
context.fillRect(startPos, GRAPH_Y, PR, GRAPH_HEIGHT);
context.fillStyle = bgColor;
context.globalAlpha = 0.9;
context.fillRect(startPos, GRAPH_Y, PR, Math.round((1 - (items[i] / maxValue)) * GRAPH_HEIGHT));
}
this.texture.update();
}
private updateText(text: string) {
const { context, bgColor, textColor, WIDTH, HEIGHT, TEXT_X, TEXT_Y, GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT } = this
context.fillStyle = bgColor;
context.globalAlpha = 1;
context.fillRect(0, 0, WIDTH, HEIGHT);
context.fillStyle = textColor;
context.fillText(text, TEXT_X, TEXT_Y);
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
context.fillStyle = bgColor;
context.globalAlpha = 0.9;
context.fillRect(GRAPH_X, GRAPH_Y, GRAPH_WIDTH, GRAPH_HEIGHT);
}
}
...@@ -55,7 +55,7 @@ export default class Container extends DisplayObject { ...@@ -55,7 +55,7 @@ export default class Container extends DisplayObject {
} }
/** /**
* 批量添加child * 批量添加child
* @param children * @param children
*/ */
addChildren<T extends DisplayObject>(...children: T[]): T[] { addChildren<T extends DisplayObject>(...children: T[]): T[] {
children.forEach((child: T) => { this.addChild(child); }) children.forEach((child: T) => { this.addChild(child); })
...@@ -167,7 +167,7 @@ export default class Container extends DisplayObject { ...@@ -167,7 +167,7 @@ export default class Container extends DisplayObject {
/** /**
* 设置child的层级索引 * 设置child的层级索引
* @param {DisplayObject} child * @param {DisplayObject} child
* @param {number} index * @param {number} index
*/ */
setChildIndex(child: DisplayObject, index: number) { setChildIndex(child: DisplayObject, index: number) {
...@@ -176,7 +176,7 @@ export default class Container extends DisplayObject { ...@@ -176,7 +176,7 @@ export default class Container extends DisplayObject {
/** /**
* 根据索引获取子级对象 * 根据索引获取子级对象
* @param {number} index * @param {number} index
* @return {DisplayObject} * @return {DisplayObject}
*/ */
getChildAt(index: number): DisplayObject { getChildAt(index: number): DisplayObject {
...@@ -188,9 +188,9 @@ export default class Container extends DisplayObject { ...@@ -188,9 +188,9 @@ export default class Container extends DisplayObject {
/** /**
* 通过名字获取子级 * 通过名字获取子级
* @param name * @param name
* @param isOnlyOne * @param isOnlyOne
* @param isRecursive * @param isRecursive
*/ */
public getChildByName(name: string | RegExp, isOnlyOne: boolean = true, isRecursive: boolean = false): any { public getChildByName(name: string | RegExp, isOnlyOne: boolean = true, isRecursive: boolean = false): any {
if (!name) return null; if (!name) return null;
...@@ -216,7 +216,7 @@ export default class Container extends DisplayObject { ...@@ -216,7 +216,7 @@ export default class Container extends DisplayObject {
/** /**
* 移除child * 移除child
* @param {DisplayObject} child * @param {DisplayObject} child
* @return {DisplayObject} * @return {DisplayObject}
*/ */
removeChild(child: DisplayObject): DisplayObject { removeChild(child: DisplayObject): DisplayObject {
...@@ -231,7 +231,7 @@ export default class Container extends DisplayObject { ...@@ -231,7 +231,7 @@ export default class Container extends DisplayObject {
/** /**
* 在index索引处移除子级对象 * 在index索引处移除子级对象
* @param {number} index * @param {number} index
* @return {DisplayObject} 移除的子级对象 * @return {DisplayObject} 移除的子级对象
*/ */
removeChildAt(index: number): DisplayObject { removeChildAt(index: number): DisplayObject {
...@@ -671,6 +671,35 @@ export default class Container extends DisplayObject { ...@@ -671,6 +671,35 @@ export default class Container extends DisplayObject {
} }
} }
} }
/**
* 操作子级的所有方法,需要维护
*/
public static _childrenOperationMethods: string[] = [
//添加子级的方法
"addChild", "addChildAt", "addChildren",
//移除子级的方法
"removeChild", "removeChildAt", "removeChildren", "removeAllChildren", "removeChildrenAt", "spliceChildren",
//获取子级的方法
"getChildAt", "getChildByName", "getChildrenByName",
//获取子级索引的方法
"getChildIndex",
//改变子级索引的方法
"setChildIndex", "swapChildren"
]
} }
Container.prototype.containerUpdateTransform = Container.prototype.updateTransform; Container.prototype.containerUpdateTransform = Container.prototype.updateTransform;
function judgeMaskEnable(mask): boolean {
if (!mask) return false;
//Shape遮罩,或者Sprite遮罩
if (mask.texture) {
mask.updateShape && mask.updateShape();//更新一下
if (!mask.texture.valid) return false;
}
//Graphics遮罩,其实这个判断也包括了Sprite的纹理为空的情况
else if (!mask.graphicsData || !mask.graphicsData.length) {
return false;
}
return true;
}
...@@ -19,7 +19,7 @@ export class Event extends HashObject { ...@@ -19,7 +19,7 @@ export class Event extends HashObject {
public static RESIZE: string = "onResize"; public static RESIZE: string = "onResize";
/** /**
* ScrollPage组件滑动到开始位置事件 * Scroll组件滑动到开始位置事件
* @property SCROLL_TO_HEAD * @property SCROLL_TO_HEAD
* @static * @static
* @since 1.1.0 * @since 1.1.0
...@@ -27,7 +27,7 @@ export class Event extends HashObject { ...@@ -27,7 +27,7 @@ export class Event extends HashObject {
*/ */
public static SCROLL_TO_HEAD: string = "onScrollToHead"; public static SCROLL_TO_HEAD: string = "onScrollToHead";
/** /**
* ScrollPage组件停止滑动事件 * Scroll组件停止滑动事件
* @property SCROLL_STOP * @property SCROLL_STOP
* @static * @static
* @since 1.1.0 * @since 1.1.0
...@@ -35,7 +35,7 @@ export class Event extends HashObject { ...@@ -35,7 +35,7 @@ export class Event extends HashObject {
*/ */
public static SCROLL_STOP: string = "onScrollStop"; public static SCROLL_STOP: string = "onScrollStop";
/** /**
* ScrollPage组件开始滑动事件 * Scroll组件开始滑动事件
* @property SCROLL_START * @property SCROLL_START
* @static * @static
* @since 1.1.0 * @since 1.1.0
...@@ -43,13 +43,17 @@ export class Event extends HashObject { ...@@ -43,13 +43,17 @@ export class Event extends HashObject {
*/ */
public static SCROLL_START: string = "onScrollStart"; public static SCROLL_START: string = "onScrollStart";
/** /**
* ScrollPage组件滑动到结束位置事件 * Scroll组件滑动到结束位置事件
* @property ON_SCROLL_TO_END * @property SCROLL_TO_END
* @static * @static
* @since 1.1.0 * @since 1.1.0
* @type {string} * @type {string}
*/ */
public static SCROLL_TO_END: string = "onScrollToEnd"; public static SCROLL_TO_END: string = "onScrollToEnd";
/**
* Scroll组件滚动时触发
*/
public static SCROLLING: string = "onScrolling";
/** /**
* 舞台初始化完成后会触发的事件 * 舞台初始化完成后会触发的事件
* @property INIT_STAGE * @property INIT_STAGE
...@@ -71,7 +75,7 @@ export class Event extends HashObject { ...@@ -71,7 +75,7 @@ export class Event extends HashObject {
/** /**
* 显示对象从舞台移出事件 * 显示对象从舞台移出事件
* @Event * @Event
* @property REMOVE_TO_STAGE * @property REMOVED_FROM_STAGE
* @type {string} * @type {string}
* @static * @static
* @public * @public
...@@ -89,7 +93,7 @@ export class Event extends HashObject { ...@@ -89,7 +93,7 @@ export class Event extends HashObject {
*/ */
public static ENTER_FRAME: string = "onEnterFrame"; public static ENTER_FRAME: string = "onEnterFrame";
/** /**
* MovieClip 播放完成事件 * AnimationClip 播放完成事件
* @Event * @Event
* @property END_FRAME * @property END_FRAME
* @type {string} * @type {string}
...@@ -98,16 +102,6 @@ export class Event extends HashObject { ...@@ -98,16 +102,6 @@ export class Event extends HashObject {
* @since 1.0.0 * @since 1.0.0
*/ */
public static END_FRAME: string = "onEndFrame"; public static END_FRAME: string = "onEndFrame";
/**
* MovieClip 帧标签事件
* @Event
* @property CALL_FRAME
* @type {string}
* @static
* @public
* @since 1.0.0
*/
public static CALL_FRAME: string = "onCallFrame";
/** /**
* 完成事件 * 完成事件
* @Event * @Event
...@@ -234,7 +228,7 @@ export class Event extends HashObject { ...@@ -234,7 +228,7 @@ export class Event extends HashObject {
} }
/** /**
* 重围事件到初始状态方便重复利用 * 重置事件
* @method reset * @method reset
* @param {string} type * @param {string} type
* @param target * @param target
......
This diff is collapsed.
...@@ -35,5 +35,5 @@ export * from "./3d"; ...@@ -35,5 +35,5 @@ export * from "./3d";
//spine //spine
export * from "./spine"; export * from "./spine";
//fps面板,后续可以加入每次drawCall,总绘制对象等等
// export * from "./Stats"; export * from "./2d/FpsPanel";
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment