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);
}
}
......@@ -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;
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 {
public static RESIZE: string = "onResize";
/**
* ScrollPage组件滑动到开始位置事件
* Scroll组件滑动到开始位置事件
* @property SCROLL_TO_HEAD
* @static
* @since 1.1.0
......@@ -27,7 +27,7 @@ export class Event extends HashObject {
*/
public static SCROLL_TO_HEAD: string = "onScrollToHead";
/**
* ScrollPage组件停止滑动事件
* Scroll组件停止滑动事件
* @property SCROLL_STOP
* @static
* @since 1.1.0
......@@ -35,7 +35,7 @@ export class Event extends HashObject {
*/
public static SCROLL_STOP: string = "onScrollStop";
/**
* ScrollPage组件开始滑动事件
* Scroll组件开始滑动事件
* @property SCROLL_START
* @static
* @since 1.1.0
......@@ -43,13 +43,17 @@ export class Event extends HashObject {
*/
public static SCROLL_START: string = "onScrollStart";
/**
* ScrollPage组件滑动到结束位置事件
* @property ON_SCROLL_TO_END
* Scroll组件滑动到结束位置事件
* @property SCROLL_TO_END
* @static
* @since 1.1.0
* @type {string}
*/
public static SCROLL_TO_END: string = "onScrollToEnd";
/**
* Scroll组件滚动时触发
*/
public static SCROLLING: string = "onScrolling";
/**
* 舞台初始化完成后会触发的事件
* @property INIT_STAGE
......@@ -71,7 +75,7 @@ export class Event extends HashObject {
/**
* 显示对象从舞台移出事件
* @Event
* @property REMOVE_TO_STAGE
* @property REMOVED_FROM_STAGE
* @type {string}
* @static
* @public
......@@ -89,7 +93,7 @@ export class Event extends HashObject {
*/
public static ENTER_FRAME: string = "onEnterFrame";
/**
* MovieClip 播放完成事件
* AnimationClip 播放完成事件
* @Event
* @property END_FRAME
* @type {string}
......@@ -98,16 +102,6 @@ export class Event extends HashObject {
* @since 1.0.0
*/
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
......@@ -234,7 +228,7 @@ export class Event extends HashObject {
}
/**
* 重围事件到初始状态方便重复利用
* 重置事件
* @method reset
* @param {string} type
* @param target
......
This diff is collapsed.
......@@ -35,5 +35,5 @@ export * from "./3d";
//spine
export * from "./spine";
// export * from "./Stats";
\ No newline at end of file
//fps面板,后续可以加入每次drawCall,总绘制对象等等
export * from "./2d/FpsPanel";
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