lyb-pixi-js 1.1.10 → 1.1.12
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.
- package/README.md +72 -40
- package/Utils/LibPixiAudio.d.ts +30 -10
- package/Utils/LibPixiAudio.js +53 -29
- package/lyb-pixi.js +68 -68
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Lib自用PixiJS组件&工具方法
|
|
1
|
+
# Lib 自用 PixiJS 组件&工具方法
|
|
2
2
|
|
|
3
3
|
## 介绍
|
|
4
4
|
|
|
@@ -18,7 +18,7 @@ import { LibPixiJs } from "lyb-pixi-js";
|
|
|
18
18
|
const text = new LibPixiJs.Base.LibPixiText({
|
|
19
19
|
text: "Hello World!",
|
|
20
20
|
fontSize: 50,
|
|
21
|
-
fontColor:"red",
|
|
21
|
+
fontColor: "red",
|
|
22
22
|
});
|
|
23
23
|
app.stage.addChild(text);
|
|
24
24
|
```
|
|
@@ -44,12 +44,12 @@ export * from "lyb-pixi-js/Base/LibPixiText";
|
|
|
44
44
|
export * from "lyb-pixi-js/Base/LibPixiRectBgColor";
|
|
45
45
|
|
|
46
46
|
//你的项目文件 index.ts
|
|
47
|
-
import { LibText,LibRectBgColor } from "utils";
|
|
47
|
+
import { LibText, LibRectBgColor } from "utils";
|
|
48
48
|
|
|
49
49
|
const text = new LibPixiText({
|
|
50
50
|
text: "Hello World!",
|
|
51
51
|
fontSize: 50,
|
|
52
|
-
fontColor:"red",
|
|
52
|
+
fontColor: "red",
|
|
53
53
|
});
|
|
54
54
|
app.stage.addChild(text);
|
|
55
55
|
|
|
@@ -69,18 +69,18 @@ app.stage.addChild(box);
|
|
|
69
69
|
<script src="https://unpkg.com/lyb-pixi-js/lyb-pixi.js"></script>
|
|
70
70
|
|
|
71
71
|
<script>
|
|
72
|
-
const text = new LibPixiJs.Base.LibPixiText({
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
});
|
|
77
|
-
app.stage.addChild(text);
|
|
72
|
+
const text = new LibPixiJs.Base.LibPixiText({
|
|
73
|
+
text: "Hello World!",
|
|
74
|
+
fontSize: 50,
|
|
75
|
+
fontColor: "red",
|
|
76
|
+
});
|
|
77
|
+
app.stage.addChild(text);
|
|
78
78
|
</script>
|
|
79
79
|
```
|
|
80
80
|
|
|
81
81
|
## 目录
|
|
82
82
|
|
|
83
|
-
###
|
|
83
|
+
### 组件
|
|
84
84
|
|
|
85
85
|
\- [LibPixiText-文本](#LibPixiText-文本)
|
|
86
86
|
|
|
@@ -114,6 +114,31 @@ app.stage.addChild(text);
|
|
|
114
114
|
|
|
115
115
|
\- [LibPixiTable-数字表格](#LibPixiTable-数字表格)
|
|
116
116
|
|
|
117
|
+
### 方法
|
|
118
|
+
|
|
119
|
+
\- [LibPixiAudio-音频播放器](#LibPixiAudio-音频播放器)
|
|
120
|
+
|
|
121
|
+
\- [LibPixiCreateNineGrid-九宫格图](#LibPixiCreateNineGrid-九宫格图)
|
|
122
|
+
|
|
123
|
+
\- [LibPixiEvent-事件注册](#LibPixiEvent-事件注册)
|
|
124
|
+
|
|
125
|
+
\- [LibPixiEventControlled-可关闭的事件](#LibPixiEventControlled-可关闭的事件)
|
|
126
|
+
|
|
127
|
+
\- [LibPixiFilter-滤镜](#LibPixiFilter-滤镜)
|
|
128
|
+
|
|
129
|
+
\- [LibPixiIntervalTrigger-间隔触发](#LibPixiIntervalTrigger-间隔触发)
|
|
130
|
+
|
|
131
|
+
\- [LibPixiOutsideClick-失焦隐藏](#LibPixiOutsideClick-失焦隐藏)
|
|
132
|
+
|
|
133
|
+
\- [LibPixiOverflowHidden-溢出裁剪](#LibPixiOverflowHidden-溢出裁剪)
|
|
134
|
+
|
|
135
|
+
\- [LibPixiPromiseTickerTimeout-TickerPromise 定时器](#LibPixiPromiseTickerTimeout-TickerPromise定时器)
|
|
136
|
+
|
|
137
|
+
\- [LibPixiScaleContainer-超出缩放](#LibPixiScaleContainer-超出缩放)
|
|
138
|
+
|
|
139
|
+
\- [LibPixiShadow-阴影](#LibPixiShadow-阴影)
|
|
140
|
+
|
|
141
|
+
\- [LibPixiTickerTimeout-Ticker 定时器](#LibPixiTickerTimeout-Ticker定时器)
|
|
117
142
|
|
|
118
143
|
## Base-基础
|
|
119
144
|
|
|
@@ -125,7 +150,7 @@ app.stage.addChild(text);
|
|
|
125
150
|
const text = new LibPixiJs.Base.LibPixiText({
|
|
126
151
|
text: "Hello World!",
|
|
127
152
|
fontSize: 50,
|
|
128
|
-
fontColor:"red",
|
|
153
|
+
fontColor: "red",
|
|
129
154
|
});
|
|
130
155
|
this.addChild(text);
|
|
131
156
|
```
|
|
@@ -194,7 +219,7 @@ this.bgSpine = new LibPixiSpine("spine_buyfree", {
|
|
|
194
219
|
onUpdate: ({ x, y, rotate, scaleX, scaleY }) => {
|
|
195
220
|
followContainer2.position.set(
|
|
196
221
|
x + 1920 / 2 - followContainer2.width / 2,
|
|
197
|
-
y + 1080 / 2 - followContainer2.height / 2
|
|
222
|
+
y + 1080 / 2 - followContainer2.height / 2
|
|
198
223
|
);
|
|
199
224
|
followContainer2.rotation = rotate;
|
|
200
225
|
followContainer2.scale.set(scaleX, scaleY);
|
|
@@ -219,7 +244,7 @@ const libPixiParticleMove = new LibPixiJs.Base.LibPixiParticleMove({
|
|
|
219
244
|
json: PIXI.Assets.get("fly.json"),
|
|
220
245
|
duration: 1,
|
|
221
246
|
showControl: true,
|
|
222
|
-
ease:"power1.in",
|
|
247
|
+
ease: "power1.in",
|
|
223
248
|
loop: true,
|
|
224
249
|
});
|
|
225
250
|
```
|
|
@@ -252,7 +277,10 @@ button.setDisabled(true); //禁用按钮
|
|
|
252
277
|
app.stage.addChild(button);
|
|
253
278
|
|
|
254
279
|
//切换按钮材质
|
|
255
|
-
button.toggleTexture(
|
|
280
|
+
button.toggleTexture(
|
|
281
|
+
Texture.from("new-default.png"),
|
|
282
|
+
Texture.from("new-hover.png")
|
|
283
|
+
);
|
|
256
284
|
```
|
|
257
285
|
|
|
258
286
|
### LibPixiCloseBtn-关闭按钮
|
|
@@ -525,13 +553,12 @@ stage.addChild(table);
|
|
|
525
553
|
const audioPlayer = new LibPixiAudio();
|
|
526
554
|
|
|
527
555
|
// 播放音效
|
|
528
|
-
audioPlayer.playEffect(
|
|
529
|
-
.
|
|
530
|
-
|
|
531
|
-
});
|
|
556
|
+
audioPlayer.playEffect("effect-link").then(() => {
|
|
557
|
+
console.log("音效播放完成");
|
|
558
|
+
});
|
|
532
559
|
|
|
533
560
|
// 播放音乐
|
|
534
|
-
audioPlayer.playMusic(
|
|
561
|
+
audioPlayer.playMusic("music-link");
|
|
535
562
|
|
|
536
563
|
// 暂停音乐
|
|
537
564
|
audioPlayer.pauseMusic();
|
|
@@ -540,7 +567,7 @@ audioPlayer.pauseMusic();
|
|
|
540
567
|
audioPlayer.resumeMusic();
|
|
541
568
|
|
|
542
569
|
// 停止指定音效
|
|
543
|
-
audioPlayer.stopEffect(
|
|
570
|
+
audioPlayer.stopEffect("effect-link");
|
|
544
571
|
|
|
545
572
|
// 设置启用音效
|
|
546
573
|
audioPlayer.setEffectEnabled(false);
|
|
@@ -567,14 +594,19 @@ const nineGrid = libPixiCreateNineGrid({
|
|
|
567
594
|
> 事件注册
|
|
568
595
|
|
|
569
596
|
```ts
|
|
570
|
-
libPixiEvent(container,
|
|
571
|
-
console.log(
|
|
597
|
+
libPixiEvent(container, "pointerdown", (e) => {
|
|
598
|
+
console.log("Pointer down event triggered", e);
|
|
572
599
|
});
|
|
573
600
|
|
|
574
601
|
// 只执行一次的事件
|
|
575
|
-
libPixiEvent(
|
|
576
|
-
|
|
577
|
-
|
|
602
|
+
libPixiEvent(
|
|
603
|
+
container,
|
|
604
|
+
"pointerup",
|
|
605
|
+
(e) => {
|
|
606
|
+
console.log("Pointer up event triggered", e);
|
|
607
|
+
},
|
|
608
|
+
true
|
|
609
|
+
);
|
|
578
610
|
```
|
|
579
611
|
|
|
580
612
|
### LibPixiEventControlled-可关闭的事件
|
|
@@ -582,8 +614,8 @@ libPixiEvent(container, 'pointerup', (e) => {
|
|
|
582
614
|
> 设置可关闭的事件监听,调用自身后不再触发
|
|
583
615
|
|
|
584
616
|
```ts
|
|
585
|
-
const closeEvent = libPixiEventControlled(container,
|
|
586
|
-
console.log(
|
|
617
|
+
const closeEvent = libPixiEventControlled(container, "pointerdown", (e) => {
|
|
618
|
+
console.log("Pointer down event triggered", e);
|
|
587
619
|
});
|
|
588
620
|
|
|
589
621
|
// 调用返回的函数关闭事件监听
|
|
@@ -595,10 +627,10 @@ closeEvent();
|
|
|
595
627
|
> 滤镜
|
|
596
628
|
|
|
597
629
|
```ts
|
|
598
|
-
const brightnessFilter = libPixiFilter(
|
|
599
|
-
const blurFilter = libPixiFilter(
|
|
600
|
-
const desaturateFilter = libPixiFilter(
|
|
601
|
-
const contrastFilter = libPixiFilter(
|
|
630
|
+
const brightnessFilter = libPixiFilter("brightness", 1.2); // 设置亮度为1.2
|
|
631
|
+
const blurFilter = libPixiFilter("blur"); // 设置模糊滤镜
|
|
632
|
+
const desaturateFilter = libPixiFilter("desaturate"); // 设置去饱和滤镜
|
|
633
|
+
const contrastFilter = libPixiFilter("contrast", 1.5); // 设置对比度为1.5
|
|
602
634
|
```
|
|
603
635
|
|
|
604
636
|
### LibPixiIntervalTrigger-间隔触发
|
|
@@ -607,13 +639,13 @@ const contrastFilter = libPixiFilter('contrast', 1.5); // 设置对比度为1.5
|
|
|
607
639
|
|
|
608
640
|
```ts
|
|
609
641
|
const stopInterval = libPixiIntervalTrigger(() => {
|
|
610
|
-
console.log(
|
|
642
|
+
console.log("Triggered interval callback");
|
|
611
643
|
}, [500, 1000]); // 随机间隔 500ms 到 1000ms
|
|
612
644
|
|
|
613
645
|
//or
|
|
614
646
|
|
|
615
647
|
const stopInterval = libPixiIntervalTrigger(() => {
|
|
616
|
-
console.log(
|
|
648
|
+
console.log("Triggered interval callback");
|
|
617
649
|
}, 500); // 间隔 500ms
|
|
618
650
|
|
|
619
651
|
// 停止间隔触发
|
|
@@ -626,7 +658,7 @@ stopInterval();
|
|
|
626
658
|
|
|
627
659
|
```ts
|
|
628
660
|
const stopOutsideClick = libPixiOutsideClick(container, button, () => {
|
|
629
|
-
console.log(
|
|
661
|
+
console.log("Container closed");
|
|
630
662
|
});
|
|
631
663
|
|
|
632
664
|
// 停止监听点击事件
|
|
@@ -641,15 +673,15 @@ stopOutsideClick();
|
|
|
641
673
|
const mask = libPixiOverflowHidden(container); // 为容器创建并应用矩形蒙版
|
|
642
674
|
```
|
|
643
675
|
|
|
644
|
-
### LibPixiPromiseTickerTimeout-TickerPromise定时器
|
|
676
|
+
### LibPixiPromiseTickerTimeout-TickerPromise 定时器
|
|
645
677
|
|
|
646
678
|
> 基于 Ticker 和 Promise 的定时器
|
|
647
679
|
|
|
648
680
|
```ts
|
|
649
681
|
libPixiPromiseTickerTimeout(1000, () => {
|
|
650
|
-
console.log(
|
|
682
|
+
console.log("Callback after 1000ms");
|
|
651
683
|
}).then(() => {
|
|
652
|
-
console.log(
|
|
684
|
+
console.log("Timer completed");
|
|
653
685
|
});
|
|
654
686
|
```
|
|
655
687
|
|
|
@@ -675,13 +707,13 @@ libPixiShadow(container, {
|
|
|
675
707
|
});
|
|
676
708
|
```
|
|
677
709
|
|
|
678
|
-
### LibPixiTickerTimeout-Ticker定时器
|
|
710
|
+
### LibPixiTickerTimeout-Ticker 定时器
|
|
679
711
|
|
|
680
712
|
> 基于 Ticker 的定时器
|
|
681
713
|
|
|
682
714
|
```ts
|
|
683
715
|
const stopTimer = libPixiTickerTimeout(() => {
|
|
684
|
-
console.log(
|
|
716
|
+
console.log("Callback after delay");
|
|
685
717
|
}, 1000);
|
|
686
718
|
|
|
687
719
|
// 停止定时器
|
package/Utils/LibPixiAudio.d.ts
CHANGED
|
@@ -15,20 +15,40 @@ export declare class LibPixiAudio {
|
|
|
15
15
|
/** 当前正在播放的音效列表 */
|
|
16
16
|
private _playingList;
|
|
17
17
|
constructor();
|
|
18
|
-
/** @description 播放音效
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/** @description
|
|
18
|
+
/** @description 播放音效
|
|
19
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
20
|
+
*/
|
|
21
|
+
playEffect(key: string): Promise<void>;
|
|
22
|
+
/** @description 播放音乐
|
|
23
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
24
|
+
*/
|
|
25
|
+
playMusic(key: string): Promise<void>;
|
|
26
|
+
/** @description 暂停音乐 */
|
|
23
27
|
pauseMusic(): void;
|
|
24
|
-
/** @description
|
|
28
|
+
/** @description 继续播放音乐 */
|
|
25
29
|
resumeMusic(): void;
|
|
26
|
-
/** @description 停止播放指定音效
|
|
30
|
+
/** @description 停止播放指定音效
|
|
31
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止
|
|
32
|
+
*/
|
|
27
33
|
stopEffect(link: string): void;
|
|
28
|
-
/** @description 设置启用音效
|
|
34
|
+
/** @description 设置启用音效
|
|
35
|
+
* @param enabled 启用状态,false为禁用
|
|
36
|
+
*/
|
|
29
37
|
setEffectEnabled(enabled: boolean): void;
|
|
30
|
-
/** @description 设置启用音乐
|
|
38
|
+
/** @description 设置启用音乐
|
|
39
|
+
* @param enabled 启用状态,false为禁用
|
|
40
|
+
*/
|
|
31
41
|
setMusicEnabled(enabled: boolean): void;
|
|
32
|
-
/** @description 设置音效和音乐播放状态
|
|
42
|
+
/** @description 设置音效和音乐播放状态
|
|
43
|
+
* @param status 播放状态,false为暂停
|
|
44
|
+
*/
|
|
33
45
|
private _setPlayStatus;
|
|
46
|
+
/** @description 设置静音音乐
|
|
47
|
+
* @param disabled 静音状态,true为静音
|
|
48
|
+
*/
|
|
49
|
+
private _setMusicMute;
|
|
50
|
+
/** @description 设置静音音效
|
|
51
|
+
* @param disabled 静音状态,true为静音
|
|
52
|
+
*/
|
|
53
|
+
private _setEffectMute;
|
|
34
54
|
}
|
package/Utils/LibPixiAudio.js
CHANGED
|
@@ -23,17 +23,38 @@ export class LibPixiAudio {
|
|
|
23
23
|
this._isBackground = false;
|
|
24
24
|
/** 当前正在播放的音效列表 */
|
|
25
25
|
this._playingList = [];
|
|
26
|
+
/** @description 设置音效和音乐播放状态
|
|
27
|
+
* @param status 播放状态,false为暂停
|
|
28
|
+
*/
|
|
29
|
+
this._setPlayStatus = (status) => {
|
|
30
|
+
if (status) {
|
|
31
|
+
!this._isMusicPaused && this._musicPlayer.play();
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this._musicPlayer.pause();
|
|
35
|
+
}
|
|
36
|
+
this._playingList.forEach((item) => {
|
|
37
|
+
if (status) {
|
|
38
|
+
item.audio.play();
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
item.audio.pause();
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
26
45
|
this._musicPlayer = new Audio();
|
|
27
46
|
document.addEventListener("visibilitychange", () => {
|
|
28
47
|
this._isBackground = document.hidden;
|
|
29
48
|
this._setPlayStatus(!document.hidden);
|
|
30
49
|
});
|
|
31
50
|
}
|
|
32
|
-
/** @description 播放音效
|
|
33
|
-
|
|
51
|
+
/** @description 播放音效
|
|
52
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
53
|
+
*/
|
|
54
|
+
playEffect(key) {
|
|
34
55
|
return new Promise((resolve) => {
|
|
35
56
|
const id = new Date().getTime();
|
|
36
|
-
const url = Assets.get(
|
|
57
|
+
const url = Assets.get(key).url;
|
|
37
58
|
const audio = new Audio(url);
|
|
38
59
|
audio.muted = this._isBackground || !this.effectEnabled;
|
|
39
60
|
audio.addEventListener("ended", () => {
|
|
@@ -52,8 +73,10 @@ export class LibPixiAudio {
|
|
|
52
73
|
.catch(() => { });
|
|
53
74
|
});
|
|
54
75
|
}
|
|
55
|
-
/** @description 播放音乐
|
|
56
|
-
|
|
76
|
+
/** @description 播放音乐
|
|
77
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源
|
|
78
|
+
*/
|
|
79
|
+
playMusic(key) {
|
|
57
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
81
|
//如果有音乐正在播放,则停止
|
|
59
82
|
if (this._musicPlayer) {
|
|
@@ -65,7 +88,7 @@ export class LibPixiAudio {
|
|
|
65
88
|
});
|
|
66
89
|
this._musicPlayer.pause();
|
|
67
90
|
}
|
|
68
|
-
const url = Assets.get(
|
|
91
|
+
const url = Assets.get(key).url;
|
|
69
92
|
this._musicPlayer.src = url;
|
|
70
93
|
this._musicPlayer.loop = true;
|
|
71
94
|
this._musicPlayer.volume = 0;
|
|
@@ -88,17 +111,19 @@ export class LibPixiAudio {
|
|
|
88
111
|
play();
|
|
89
112
|
});
|
|
90
113
|
}
|
|
91
|
-
/** @description
|
|
114
|
+
/** @description 暂停音乐 */
|
|
92
115
|
pauseMusic() {
|
|
93
116
|
this._isMusicPaused = true;
|
|
94
117
|
this._musicPlayer.pause();
|
|
95
118
|
}
|
|
96
|
-
/** @description
|
|
119
|
+
/** @description 继续播放音乐 */
|
|
97
120
|
resumeMusic() {
|
|
98
121
|
this._isMusicPaused = false;
|
|
99
122
|
this._musicPlayer.play();
|
|
100
123
|
}
|
|
101
|
-
/** @description 停止播放指定音效
|
|
124
|
+
/** @description 停止播放指定音效
|
|
125
|
+
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止
|
|
126
|
+
*/
|
|
102
127
|
stopEffect(link) {
|
|
103
128
|
const url = Assets.get(link).url;
|
|
104
129
|
this._playingList.forEach((item) => {
|
|
@@ -108,33 +133,32 @@ export class LibPixiAudio {
|
|
|
108
133
|
});
|
|
109
134
|
this._playingList = this._playingList.filter((item) => item.url !== url);
|
|
110
135
|
}
|
|
111
|
-
/** @description 设置启用音效
|
|
136
|
+
/** @description 设置启用音效
|
|
137
|
+
* @param enabled 启用状态,false为禁用
|
|
138
|
+
*/
|
|
112
139
|
setEffectEnabled(enabled) {
|
|
113
140
|
this.effectEnabled = enabled;
|
|
114
|
-
this.
|
|
115
|
-
item.audio.muted = !enabled;
|
|
116
|
-
});
|
|
141
|
+
this._setEffectMute(!enabled);
|
|
117
142
|
}
|
|
118
|
-
/** @description 设置启用音乐
|
|
143
|
+
/** @description 设置启用音乐
|
|
144
|
+
* @param enabled 启用状态,false为禁用
|
|
145
|
+
*/
|
|
119
146
|
setMusicEnabled(enabled) {
|
|
120
147
|
this.musicEnabled = enabled;
|
|
121
|
-
this.
|
|
148
|
+
this._setMusicMute(!enabled);
|
|
149
|
+
}
|
|
150
|
+
/** @description 设置静音音乐
|
|
151
|
+
* @param disabled 静音状态,true为静音
|
|
152
|
+
*/
|
|
153
|
+
_setMusicMute(disabled) {
|
|
154
|
+
this._musicPlayer.muted = disabled || !this.musicEnabled;
|
|
122
155
|
}
|
|
123
|
-
/** @description
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
this._musicPlayer.pause();
|
|
130
|
-
}
|
|
156
|
+
/** @description 设置静音音效
|
|
157
|
+
* @param disabled 静音状态,true为静音
|
|
158
|
+
*/
|
|
159
|
+
_setEffectMute(disabled) {
|
|
131
160
|
this._playingList.forEach((item) => {
|
|
132
|
-
|
|
133
|
-
item.audio.play();
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
item.audio.pause();
|
|
137
|
-
}
|
|
161
|
+
item.audio.muted = disabled || !this.effectEnabled;
|
|
138
162
|
});
|
|
139
163
|
}
|
|
140
164
|
}
|