lyb-pixi-js 1.4.5 → 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 { Application, Container } from "pixi.js";
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 _setTxtInfo;
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, UPDATE_PRIORITY, Ticker, } from "pixi.js";
2
- import { LibPixiText } from '../Base/LibPixiText';
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._paramTxts = [];
25
- for (let i = 0; i < 3; i++) {
26
- const txt = new LibPixiText({
27
- text: "",
28
- fontWeight: "bold",
29
- fontSize: 36,
30
- shadow: ["#000", 45, 3, 5],
31
- fontColor: "#fff",
32
- });
33
- this._paramTxts[i] = txt;
34
- txt.x = 0;
35
- txt.y = txt.height * i;
36
- this.addChild(txt);
37
- txt.alpha = 0.75;
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._setTxtInfo(0, Math.floor(fps).toFixed(0));
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._setTxtInfo(1, this._drawCount);
67
- this._setTxtInfo(2, this._maxDrawCount);
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
- _setTxtInfo(p, v) {
73
- const fpsColor = (v) => {
74
- this._paramTxts[p].style.fill = "#fff";
75
- if (v <= 30) {
76
- this._paramTxts[p].style.fill = "yellow";
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 paramMapping = [
92
- () => {
93
- fpsColor(v);
94
- return `Fps:${v}`;
95
- },
96
- () => {
97
- drawCallColor(v);
98
- return `Draw Call:${v}`;
99
- },
100
- () => {
101
- drawCallColor(v);
102
- return `Max Draw Call:${v}`;
103
- },
104
- ];
105
- this._paramTxts[p].text = paramMapping[p]();
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
  }