lyb-pixi-js 1.4.4 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Container, type Application } from "pixi.js";
|
|
2
2
|
/** @description 监视帧率、Draw Call、Max Draw Call
|
|
3
3
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPerforMon-性能监视器
|
|
4
4
|
*/
|
|
@@ -17,15 +17,30 @@ export declare class LibPixiPerforMon extends Container {
|
|
|
17
17
|
private _tempMaxDrawCount;
|
|
18
18
|
/** 上次收集数据的时间 */
|
|
19
19
|
private _lastCollectTime;
|
|
20
|
+
/** 整体宽度 */
|
|
21
|
+
private _containerWidth;
|
|
22
|
+
/** 整体高度 */
|
|
23
|
+
private _containerHeight;
|
|
20
24
|
/** 渲染器 */
|
|
21
25
|
private _renderer;
|
|
22
|
-
/** 存储每个性能指标的文本对象 */
|
|
23
|
-
private _paramTxts;
|
|
24
26
|
/** 原始的 drawElements 方法 */
|
|
25
27
|
private _drawElements;
|
|
28
|
+
/** 背景 */
|
|
29
|
+
private _bg;
|
|
30
|
+
/** FPS文本 */
|
|
31
|
+
private _fpsText;
|
|
32
|
+
/** Draw Call文本 */
|
|
33
|
+
private _drawCallText;
|
|
34
|
+
/** Max Draw Call文本 */
|
|
35
|
+
private _maxDrawCallText;
|
|
26
36
|
constructor(app: Application);
|
|
27
37
|
/** @description 初始化显示性能数据 */
|
|
28
38
|
init(): void;
|
|
29
39
|
/** @description 更新文本信息 */
|
|
30
|
-
private
|
|
40
|
+
private _setTextInfo;
|
|
41
|
+
/** @description 获取FPS颜色 */
|
|
42
|
+
getFpsColor(v: number): string;
|
|
43
|
+
/** @description 获取Draw Call颜色 */
|
|
44
|
+
getDrawCallColor(v: number): string;
|
|
45
|
+
private _resize;
|
|
31
46
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Container,
|
|
2
|
-
import {
|
|
1
|
+
import { Container, Ticker, UPDATE_PRIORITY, } from "pixi.js";
|
|
2
|
+
import { LibPixiRectBgColor } from "../Base/LibPixiRectBgColor";
|
|
3
|
+
import { LibPixiText } from "../Base/LibPixiText";
|
|
3
4
|
/** @description 监视帧率、Draw Call、Max Draw Call
|
|
4
5
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiPerforMon-性能监视器
|
|
5
6
|
*/
|
|
@@ -20,22 +21,39 @@ export class LibPixiPerforMon extends Container {
|
|
|
20
21
|
this._tempMaxDrawCount = 0;
|
|
21
22
|
/** 上次收集数据的时间 */
|
|
22
23
|
this._lastCollectTime = 0;
|
|
23
|
-
/**
|
|
24
|
-
this.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
24
|
+
/** 整体宽度 */
|
|
25
|
+
this._containerWidth = 580;
|
|
26
|
+
/** 整体高度 */
|
|
27
|
+
this._containerHeight = 50;
|
|
28
|
+
this.pivot.x = this._containerWidth / 2;
|
|
29
|
+
this._resize(window.innerWidth, window.innerHeight);
|
|
30
|
+
window.addEventListener("resize", () => {
|
|
31
|
+
this._resize(window.innerWidth, window.innerHeight);
|
|
32
|
+
});
|
|
33
|
+
//创建背景
|
|
34
|
+
this._bg = new LibPixiRectBgColor({
|
|
35
|
+
width: this._containerWidth,
|
|
36
|
+
height: this._containerHeight,
|
|
37
|
+
bgColor: "#000",
|
|
38
|
+
alpha: 0.75,
|
|
39
|
+
});
|
|
40
|
+
this.addChild(this._bg);
|
|
41
|
+
//创建内容容器
|
|
42
|
+
const content = new Container();
|
|
43
|
+
this.addChild(content);
|
|
44
|
+
content.x = 25;
|
|
45
|
+
content.y = this._containerHeight / 2;
|
|
46
|
+
//创建FPS文本
|
|
47
|
+
this._fpsText = new TextBox("FPS");
|
|
48
|
+
content.addChild(this._fpsText);
|
|
49
|
+
//创建Draw Call文本
|
|
50
|
+
this._drawCallText = new TextBox("Draw Call");
|
|
51
|
+
content.addChild(this._drawCallText);
|
|
52
|
+
this._drawCallText.x = 125;
|
|
53
|
+
//创建Max Draw Call文本
|
|
54
|
+
this._maxDrawCallText = new TextBox("Max Draw Call");
|
|
55
|
+
content.addChild(this._maxDrawCallText);
|
|
56
|
+
this._maxDrawCallText.x = 310;
|
|
39
57
|
this._renderer = app.renderer;
|
|
40
58
|
this._drawElements = this._renderer["gl"].drawElements;
|
|
41
59
|
this.init();
|
|
@@ -50,7 +68,7 @@ export class LibPixiPerforMon extends Container {
|
|
|
50
68
|
const fps = Ticker.system.FPS;
|
|
51
69
|
this._nowTime = performance.now();
|
|
52
70
|
if (this._nowTime - this._lastTime >= 100.0) {
|
|
53
|
-
this.
|
|
71
|
+
this._setTextInfo("fps", Number(Math.floor(fps).toFixed(0)));
|
|
54
72
|
this._lastTime = this._nowTime;
|
|
55
73
|
}
|
|
56
74
|
if (this._nowTime - this._lastCollectTime < this.COLLECT_TIME) {
|
|
@@ -63,45 +81,84 @@ export class LibPixiPerforMon extends Container {
|
|
|
63
81
|
this._tempMaxDrawCount = 0;
|
|
64
82
|
this._lastCollectTime = this._nowTime;
|
|
65
83
|
}
|
|
66
|
-
this.
|
|
67
|
-
this.
|
|
84
|
+
this._setTextInfo("drawCall", this._drawCount);
|
|
85
|
+
this._setTextInfo("maxDrawCall", this._maxDrawCount);
|
|
68
86
|
this._drawCount = 0;
|
|
69
87
|
}, UPDATE_PRIORITY.UTILITY);
|
|
70
88
|
}
|
|
71
89
|
/** @description 更新文本信息 */
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
if (v <= 20) {
|
|
79
|
-
this._paramTxts[p].style.fill = "red";
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const drawCallColor = (v) => {
|
|
83
|
-
this._paramTxts[p].style.fill = "#fff";
|
|
84
|
-
if (v >= 75) {
|
|
85
|
-
this._paramTxts[p].style.fill = "yellow";
|
|
86
|
-
}
|
|
87
|
-
if (v >= 100) {
|
|
88
|
-
this._paramTxts[p].style.fill = "red";
|
|
89
|
-
}
|
|
90
|
+
_setTextInfo(p, v) {
|
|
91
|
+
const textObj = {
|
|
92
|
+
fps: this._fpsText,
|
|
93
|
+
drawCall: this._drawCallText,
|
|
94
|
+
maxDrawCall: this._maxDrawCallText,
|
|
90
95
|
};
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
96
|
+
const textBox = textObj[p];
|
|
97
|
+
textBox.updateValue(v);
|
|
98
|
+
if (p === "fps") {
|
|
99
|
+
textBox.updateColor(this.getFpsColor(v));
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
textBox.updateColor(this.getDrawCallColor(v));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** @description 获取FPS颜色 */
|
|
106
|
+
getFpsColor(v) {
|
|
107
|
+
let color = "#00ff04";
|
|
108
|
+
if (v < 30) {
|
|
109
|
+
color = "#ffd20a";
|
|
110
|
+
}
|
|
111
|
+
if (v < 20) {
|
|
112
|
+
color = "#ff000d";
|
|
113
|
+
}
|
|
114
|
+
return color;
|
|
115
|
+
}
|
|
116
|
+
/** @description 获取Draw Call颜色 */
|
|
117
|
+
getDrawCallColor(v) {
|
|
118
|
+
let color = "#00ff04";
|
|
119
|
+
if (v >= 75) {
|
|
120
|
+
color = "#ffd20a";
|
|
121
|
+
}
|
|
122
|
+
if (v >= 100) {
|
|
123
|
+
color = "#ff000d";
|
|
124
|
+
}
|
|
125
|
+
return color;
|
|
126
|
+
}
|
|
127
|
+
_resize(w, h) {
|
|
128
|
+
if (w > h) {
|
|
129
|
+
this.x = 1920 / 2;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
this.x = 1080 / 2;
|
|
133
|
+
}
|
|
134
|
+
console.log(this.x);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
class TextBox extends Container {
|
|
138
|
+
constructor(text, fontSize = 26) {
|
|
139
|
+
super();
|
|
140
|
+
const label = new LibPixiText({
|
|
141
|
+
text,
|
|
142
|
+
fontSize,
|
|
143
|
+
fontWeight: "bold",
|
|
144
|
+
});
|
|
145
|
+
this.addChild(label);
|
|
146
|
+
label.anchor.y = 0.5;
|
|
147
|
+
this._valueText = new LibPixiText({
|
|
148
|
+
text: "0",
|
|
149
|
+
fontSize,
|
|
150
|
+
fontWeight: "bold",
|
|
151
|
+
});
|
|
152
|
+
this.addChild(this._valueText);
|
|
153
|
+
this._valueText.anchor.y = 0.5;
|
|
154
|
+
this._valueText.x = label.width + 10;
|
|
155
|
+
}
|
|
156
|
+
/** @description 更改颜色 */
|
|
157
|
+
updateColor(color) {
|
|
158
|
+
this._valueText.style.fill = color;
|
|
159
|
+
}
|
|
160
|
+
/** @description 设置数值 */
|
|
161
|
+
updateValue(value) {
|
|
162
|
+
this._valueText.text = value;
|
|
106
163
|
}
|
|
107
164
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Graphics } from "pixi.js";
|
|
2
2
|
import gsap from "gsap";
|
|
3
|
-
import { LibPixiContainer } from
|
|
3
|
+
import { LibPixiContainer } from '../Base/LibPixiContainer';
|
|
4
4
|
/** @description 通过鼠标或手指拖动数字列选择数字
|
|
5
5
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollNum-数字滑动
|
|
6
6
|
*/
|
|
@@ -89,7 +89,7 @@ export class LibPixiScrollNum extends LibPixiContainer {
|
|
|
89
89
|
this._currentIndex = index;
|
|
90
90
|
gsap.to(this._slideArea, {
|
|
91
91
|
y: -this._currentIndex * this._slideHeight + this._scrollHeight / 2,
|
|
92
|
-
duration: 0.
|
|
92
|
+
duration: 0.1,
|
|
93
93
|
onUpdate: () => {
|
|
94
94
|
var _a;
|
|
95
95
|
(_a = this._scrollCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._slideArea.y, this._currentIndex);
|