lyb-pixi-js 1.1.13 → 1.1.15
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/Components/Custom/LibPixiButtonHover.d.ts +13 -5
- package/Components/Custom/LibPixiButtonHover.js +19 -10
- package/Components/Custom/LibPixiSubAddMinMax.d.ts +12 -12
- package/Components/Custom/LibPixiSubAddMinMax.js +15 -35
- package/README.md +68 -71
- package/Utils/LibPixiAudio.d.ts +2 -1
- package/Utils/LibPixiAudio.js +18 -13
- package/lyb-pixi.js +69 -69
- package/package.json +2 -1
|
@@ -2,23 +2,31 @@ import { Container, type Texture } from "pixi.js";
|
|
|
2
2
|
export interface LibPixiButtonHoverParams {
|
|
3
3
|
/** 图标资源 */
|
|
4
4
|
texture: Texture;
|
|
5
|
-
/**
|
|
6
|
-
hoverTexture
|
|
7
|
-
/**
|
|
5
|
+
/** 悬浮图标,type为"texture"时生效 */
|
|
6
|
+
hoverTexture?: Texture;
|
|
7
|
+
/** 默认颜色 */
|
|
8
8
|
tintColor?: string;
|
|
9
|
+
/** 悬浮颜色,默认白色 */
|
|
10
|
+
hoverTintColor?: string;
|
|
11
|
+
/** 置灰颜色 */
|
|
12
|
+
disabledColor?: string;
|
|
9
13
|
}
|
|
10
14
|
/** @description 悬浮切换材质
|
|
11
15
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiButtonHover-按钮悬浮
|
|
12
16
|
*/
|
|
13
17
|
export declare class LibPixiButtonHover extends Container {
|
|
18
|
+
/** 是否被禁用 */
|
|
19
|
+
private disabled;
|
|
14
20
|
/** 按钮 */
|
|
15
21
|
private _btn;
|
|
16
22
|
/** 默认材质 */
|
|
17
23
|
private _texture;
|
|
18
24
|
/** 悬浮材质 */
|
|
19
|
-
private _hoverTexture
|
|
20
|
-
/**
|
|
25
|
+
private _hoverTexture?;
|
|
26
|
+
/** 默认颜色 */
|
|
21
27
|
private _tintColor?;
|
|
28
|
+
/** 置灰颜色 */
|
|
29
|
+
private _disabledColor;
|
|
22
30
|
constructor(params: LibPixiButtonHoverParams);
|
|
23
31
|
/** @description 切换材质
|
|
24
32
|
* @param texture 默认材质
|
|
@@ -6,22 +6,29 @@ import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
|
6
6
|
export class LibPixiButtonHover extends Container {
|
|
7
7
|
constructor(params) {
|
|
8
8
|
super();
|
|
9
|
-
|
|
9
|
+
/** 是否被禁用 */
|
|
10
|
+
this.disabled = false;
|
|
11
|
+
const { texture, hoverTexture, tintColor, hoverTintColor = "#fff", disabledColor = "#999", } = params;
|
|
10
12
|
this._texture = texture;
|
|
11
13
|
this._hoverTexture = hoverTexture;
|
|
12
14
|
this._tintColor = tintColor;
|
|
13
|
-
|
|
14
|
-
const iconBox = new Container();
|
|
15
|
-
this.addChild(iconBox);
|
|
15
|
+
this._disabledColor = disabledColor;
|
|
16
16
|
//创建图标
|
|
17
17
|
this._btn = new Sprite(texture);
|
|
18
|
-
|
|
18
|
+
this.addChild(this._btn);
|
|
19
|
+
this._btn.anchor.set(0.5);
|
|
19
20
|
tintColor && (this._btn.tint = tintColor);
|
|
20
|
-
libPixiEvent(
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
libPixiEvent(this._btn, "pointerenter", () => {
|
|
22
|
+
if (this.disabled)
|
|
23
|
+
return;
|
|
24
|
+
this._btn.tint = hoverTintColor;
|
|
25
|
+
if (this._hoverTexture) {
|
|
26
|
+
this._btn._texture = this._hoverTexture;
|
|
27
|
+
}
|
|
23
28
|
});
|
|
24
|
-
libPixiEvent(
|
|
29
|
+
libPixiEvent(this._btn, "pointerleave", () => {
|
|
30
|
+
if (this.disabled)
|
|
31
|
+
return;
|
|
25
32
|
this._btn._texture = this._texture;
|
|
26
33
|
tintColor && (this._btn.tint = tintColor);
|
|
27
34
|
});
|
|
@@ -39,6 +46,8 @@ export class LibPixiButtonHover extends Container {
|
|
|
39
46
|
* @param status 状态
|
|
40
47
|
*/
|
|
41
48
|
setDisabled(status) {
|
|
42
|
-
this.
|
|
49
|
+
this.disabled = status;
|
|
50
|
+
this._btn.tint = status ? this._disabledColor : this._tintColor || "#fff";
|
|
51
|
+
this._btn.texture = this._texture;
|
|
43
52
|
}
|
|
44
53
|
}
|
|
@@ -12,25 +12,27 @@ export interface LibPixiSubAddMinMaxParams {
|
|
|
12
12
|
initialBetIndex: number;
|
|
13
13
|
/** 下注金额列表 */
|
|
14
14
|
betAmountListLength: number;
|
|
15
|
-
/** 金额更新回调
|
|
15
|
+
/** 金额更新回调
|
|
16
|
+
* @param index 金额索引
|
|
17
|
+
*/
|
|
16
18
|
onAmountIndex: (index: number) => void;
|
|
19
|
+
/** 按钮置灰状态回调
|
|
20
|
+
* @param type 被置灰的按钮类型
|
|
21
|
+
*/
|
|
22
|
+
onDisabled: (type?: "min" | "max") => void;
|
|
17
23
|
}
|
|
18
24
|
/** @description 最小、最大按钮和增减按钮功能及置灰逻辑
|
|
19
25
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSubAddMinMax-数字控制器
|
|
20
26
|
*/
|
|
21
27
|
export declare class LibPixiSubAddMinMax {
|
|
22
28
|
/** 步进器 */
|
|
23
|
-
private
|
|
24
|
-
/** 最大最小按钮 */
|
|
25
|
-
private minBtn;
|
|
26
|
-
private maxBtn;
|
|
27
|
-
/** 增加减少按钮 */
|
|
28
|
-
private subBtn;
|
|
29
|
-
private addBtn;
|
|
29
|
+
private _baseNumSteper;
|
|
30
30
|
/** 金额列表数量 */
|
|
31
|
-
private
|
|
31
|
+
private _betAmountListLength;
|
|
32
32
|
/** 金额更新回调 */
|
|
33
|
-
onAmountIndex
|
|
33
|
+
private onAmountIndex;
|
|
34
|
+
/** 按钮置灰状态回调 */
|
|
35
|
+
private onDisabled;
|
|
34
36
|
constructor(params: LibPixiSubAddMinMaxParams);
|
|
35
37
|
/** @description 点击最小按钮 */
|
|
36
38
|
min(): void;
|
|
@@ -44,6 +46,4 @@ export declare class LibPixiSubAddMinMax {
|
|
|
44
46
|
* @param index 索引
|
|
45
47
|
*/
|
|
46
48
|
minMaxUpdateIndex(index: number): void;
|
|
47
|
-
/** @description 设置最大最小按钮置灰及恢复 */
|
|
48
|
-
private _setGrey;
|
|
49
49
|
}
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { LibJsNumberStepper } from 'lyb-js/Misc/LibJsNumberStepper.js';
|
|
1
|
+
import { LibJsNumberStepper } from "lyb-js/Misc/LibJsNumberStepper.js";
|
|
3
2
|
/** @description 最小、最大按钮和增减按钮功能及置灰逻辑
|
|
4
3
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSubAddMinMax-数字控制器
|
|
5
4
|
*/
|
|
6
5
|
export class LibPixiSubAddMinMax {
|
|
7
6
|
constructor(params) {
|
|
8
7
|
/** 金额列表数量 */
|
|
9
|
-
this.
|
|
10
|
-
const {
|
|
11
|
-
this.minBtn = minBtn;
|
|
12
|
-
this.maxBtn = maxBtn;
|
|
13
|
-
this.subBtn = subBtn;
|
|
14
|
-
this.addBtn = addBtn;
|
|
8
|
+
this._betAmountListLength = 0;
|
|
9
|
+
const { initialBetIndex, betAmountListLength, onAmountIndex, onDisabled } = params;
|
|
15
10
|
this.onAmountIndex = onAmountIndex;
|
|
16
|
-
this.
|
|
11
|
+
this.onDisabled = onDisabled;
|
|
12
|
+
this._betAmountListLength = betAmountListLength;
|
|
17
13
|
//金额增减步进器
|
|
18
|
-
this.
|
|
19
|
-
(index) => {
|
|
14
|
+
this._baseNumSteper = new LibJsNumberStepper(betAmountListLength, (index) => {
|
|
20
15
|
this.onAmountIndex(index);
|
|
21
16
|
this.minMaxUpdateIndex(index);
|
|
22
17
|
});
|
|
23
18
|
//设置初始状态
|
|
24
19
|
this.minMaxUpdateIndex(initialBetIndex);
|
|
25
|
-
this.
|
|
20
|
+
this._baseNumSteper.updateIndex(initialBetIndex);
|
|
26
21
|
}
|
|
27
22
|
/** @description 点击最小按钮 */
|
|
28
23
|
min() {
|
|
@@ -31,46 +26,31 @@ export class LibPixiSubAddMinMax {
|
|
|
31
26
|
}
|
|
32
27
|
/** @description 点击最大按钮 */
|
|
33
28
|
max() {
|
|
34
|
-
const index = this.
|
|
29
|
+
const index = this._betAmountListLength - 1;
|
|
35
30
|
this.minMaxUpdateIndex(index);
|
|
36
31
|
this.onAmountIndex(index);
|
|
37
32
|
}
|
|
38
33
|
/** @description 点击减少按钮 */
|
|
39
34
|
sub() {
|
|
40
|
-
this.
|
|
35
|
+
this._baseNumSteper.down("sub");
|
|
41
36
|
}
|
|
42
37
|
/** @description 点击增加按钮 */
|
|
43
38
|
add() {
|
|
44
|
-
this.
|
|
39
|
+
this._baseNumSteper.down("add");
|
|
45
40
|
}
|
|
46
41
|
/** @description 改变最小最大按钮状态及回调
|
|
47
42
|
* @param index 索引
|
|
48
43
|
*/
|
|
49
44
|
minMaxUpdateIndex(index) {
|
|
50
45
|
if (index === 0) {
|
|
51
|
-
this.
|
|
46
|
+
this.onDisabled("min");
|
|
52
47
|
}
|
|
53
|
-
else if (index === this.
|
|
54
|
-
this.
|
|
48
|
+
else if (index === this._betAmountListLength - 1) {
|
|
49
|
+
this.onDisabled("max");
|
|
55
50
|
}
|
|
56
51
|
else {
|
|
57
|
-
this.
|
|
58
|
-
}
|
|
59
|
-
this.baseNumSteper.updateIndex(index);
|
|
60
|
-
}
|
|
61
|
-
/** @description 设置最大最小按钮置灰及恢复 */
|
|
62
|
-
_setGrey(type) {
|
|
63
|
-
this.minBtn.filters = [];
|
|
64
|
-
this.maxBtn.filters = [];
|
|
65
|
-
this.subBtn.filters = [];
|
|
66
|
-
this.addBtn.filters = [];
|
|
67
|
-
if (type === "min") {
|
|
68
|
-
this.minBtn.filters = [libPixiFilter("desaturate")];
|
|
69
|
-
this.subBtn.filters = [libPixiFilter("desaturate")];
|
|
70
|
-
}
|
|
71
|
-
else if (type === "max") {
|
|
72
|
-
this.maxBtn.filters = [libPixiFilter("desaturate")];
|
|
73
|
-
this.addBtn.filters = [libPixiFilter("desaturate")];
|
|
52
|
+
this.onDisabled();
|
|
74
53
|
}
|
|
54
|
+
this._baseNumSteper.updateIndex(index);
|
|
75
55
|
}
|
|
76
56
|
}
|
package/README.md
CHANGED
|
@@ -256,31 +256,29 @@ const libPixiParticleMove = new LibPixiJs.Base.LibPixiParticleMove({
|
|
|
256
256
|
> 悬浮切换材质
|
|
257
257
|
|
|
258
258
|
```ts
|
|
259
|
-
import {
|
|
260
|
-
import { LibPixiButtonHover } from "./path/to/LibPixiButtonHover";
|
|
261
|
-
|
|
262
|
-
//加载材质资源
|
|
263
|
-
const defaultTexture: Texture = Texture.from("default-icon.png");
|
|
264
|
-
const hoverTexture: Texture = Texture.from("hover-icon.png");
|
|
259
|
+
import { LibPixiButtonHover } from "lyb-pixi-js";
|
|
265
260
|
|
|
266
261
|
//创建按钮实例
|
|
267
262
|
const button = new LibPixiButtonHover({
|
|
268
|
-
texture:
|
|
269
|
-
hoverTexture:
|
|
270
|
-
tintColor: "#
|
|
263
|
+
texture: PIXI.Texture.from('path/to/normal.png'),
|
|
264
|
+
hoverTexture: PIXI.Texture.from('path/to/hover.png'),
|
|
265
|
+
tintColor: "#ff0000", //默认颜色
|
|
266
|
+
hoverTintColor: "#00ff00", //悬浮颜色
|
|
267
|
+
disabledColor: "#cccccc" //禁用颜色
|
|
271
268
|
});
|
|
272
269
|
|
|
273
|
-
|
|
274
|
-
button.setDisabled(
|
|
275
|
-
|
|
276
|
-
//在Pixi.js应用的容器中添加按钮
|
|
277
|
-
app.stage.addChild(button);
|
|
270
|
+
//启用/禁用按钮
|
|
271
|
+
button.setDisabled(false); //启用
|
|
272
|
+
button.setDisabled(true); //禁用
|
|
278
273
|
|
|
279
274
|
//切换按钮材质
|
|
280
275
|
button.toggleTexture(
|
|
281
|
-
Texture.from(
|
|
282
|
-
Texture.from(
|
|
276
|
+
PIXI.Texture.from('path/to/new_normal.png'),
|
|
277
|
+
PIXI.Texture.from('path/to/new_hover.png')
|
|
283
278
|
);
|
|
279
|
+
|
|
280
|
+
//添加到Pixi舞台
|
|
281
|
+
app.stage.addChild(button);
|
|
284
282
|
```
|
|
285
283
|
|
|
286
284
|
### LibPixiCloseBtn-关闭按钮
|
|
@@ -477,40 +475,39 @@ slider.next();
|
|
|
477
475
|
> 最小、最大按钮和增减按钮功能及置灰逻辑
|
|
478
476
|
|
|
479
477
|
```ts
|
|
480
|
-
import { LibPixiSubAddMinMax } from "
|
|
481
|
-
import { Container } from "pixi.js";
|
|
478
|
+
import { LibPixiSubAddMinMax } from "lyb-pixi-js";
|
|
482
479
|
|
|
483
|
-
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
initialBetIndex,
|
|
505
|
-
betAmountListLength,
|
|
506
|
-
onAmountIndex,
|
|
480
|
+
//创建按钮实例
|
|
481
|
+
const betControl = new LibPixiSubAddMinMax({
|
|
482
|
+
minBtn: minButton, //最小按钮
|
|
483
|
+
maxBtn: maxButton, //最大按钮
|
|
484
|
+
subBtn: subButton, //减少按钮
|
|
485
|
+
addBtn: addButton, //增加按钮
|
|
486
|
+
initialBetIndex: 0, //初始下注索引
|
|
487
|
+
betAmountListLength: 10, //下注金额列表长度
|
|
488
|
+
onAmountIndex: (index) => {
|
|
489
|
+
console.log("当前下注金额索引:", index);
|
|
490
|
+
},
|
|
491
|
+
onDisabled: (type) => {
|
|
492
|
+
if (type === "min") {
|
|
493
|
+
minButton.tint = 0x999999; //禁用最小按钮
|
|
494
|
+
} else if (type === "max") {
|
|
495
|
+
maxButton.tint = 0x999999; //禁用最大按钮
|
|
496
|
+
} else {
|
|
497
|
+
minButton.tint = 0xFFFFFF; //启用最小按钮
|
|
498
|
+
maxButton.tint = 0xFFFFFF; //启用最大按钮
|
|
499
|
+
}
|
|
500
|
+
}
|
|
507
501
|
});
|
|
508
502
|
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
503
|
+
//设置初始状态
|
|
504
|
+
betControl.min(); //设置为最小值
|
|
505
|
+
betControl.max(); //设置为最大值
|
|
506
|
+
betControl.sub(); //减少下注
|
|
507
|
+
betControl.add(); //增加下注
|
|
508
|
+
|
|
509
|
+
//添加到Pixi舞台
|
|
510
|
+
app.stage.addChild(minButton, maxButton, subButton, addButton);
|
|
514
511
|
```
|
|
515
512
|
|
|
516
513
|
### LibPixiTable-数字表格
|
|
@@ -552,27 +549,27 @@ stage.addChild(table);
|
|
|
552
549
|
```ts
|
|
553
550
|
const audioPlayer = new LibPixiAudio();
|
|
554
551
|
|
|
555
|
-
|
|
552
|
+
//播放音效
|
|
556
553
|
audioPlayer.playEffect("effect-link").then(() => {
|
|
557
554
|
console.log("音效播放完成");
|
|
558
555
|
});
|
|
559
556
|
|
|
560
|
-
|
|
557
|
+
//播放音乐
|
|
561
558
|
audioPlayer.playMusic("music-link");
|
|
562
559
|
|
|
563
|
-
|
|
560
|
+
//暂停音乐
|
|
564
561
|
audioPlayer.pauseMusic();
|
|
565
562
|
|
|
566
|
-
|
|
563
|
+
//继续播放音乐
|
|
567
564
|
audioPlayer.resumeMusic();
|
|
568
565
|
|
|
569
|
-
|
|
566
|
+
//停止指定音效
|
|
570
567
|
audioPlayer.stopEffect("effect-link");
|
|
571
568
|
|
|
572
|
-
|
|
569
|
+
//设置启用音效
|
|
573
570
|
audioPlayer.setEffectEnabled(false);
|
|
574
571
|
|
|
575
|
-
|
|
572
|
+
//设置启用音乐
|
|
576
573
|
audioPlayer.setMusicEnabled(false);
|
|
577
574
|
```
|
|
578
575
|
|
|
@@ -582,10 +579,10 @@ audioPlayer.setMusicEnabled(false);
|
|
|
582
579
|
|
|
583
580
|
```ts
|
|
584
581
|
const nineGrid = libPixiCreateNineGrid({
|
|
585
|
-
texture: yourTexture,
|
|
586
|
-
dotWidth: 10,
|
|
587
|
-
width: 200,
|
|
588
|
-
height: 150,
|
|
582
|
+
texture: yourTexture, //传入纹理
|
|
583
|
+
dotWidth: 10, //四个角的宽度,可以是数字或者数组
|
|
584
|
+
width: 200, //宽度
|
|
585
|
+
height: 150, //高度
|
|
589
586
|
});
|
|
590
587
|
```
|
|
591
588
|
|
|
@@ -598,7 +595,7 @@ libPixiEvent(container, "pointerdown", (e) => {
|
|
|
598
595
|
console.log("Pointer down event triggered", e);
|
|
599
596
|
});
|
|
600
597
|
|
|
601
|
-
|
|
598
|
+
//只执行一次的事件
|
|
602
599
|
libPixiEvent(
|
|
603
600
|
container,
|
|
604
601
|
"pointerup",
|
|
@@ -618,7 +615,7 @@ const closeEvent = libPixiEventControlled(container, "pointerdown", (e) => {
|
|
|
618
615
|
console.log("Pointer down event triggered", e);
|
|
619
616
|
});
|
|
620
617
|
|
|
621
|
-
|
|
618
|
+
//调用返回的函数关闭事件监听
|
|
622
619
|
closeEvent();
|
|
623
620
|
```
|
|
624
621
|
|
|
@@ -627,10 +624,10 @@ closeEvent();
|
|
|
627
624
|
> 滤镜
|
|
628
625
|
|
|
629
626
|
```ts
|
|
630
|
-
const brightnessFilter = libPixiFilter("brightness", 1.2);
|
|
631
|
-
const blurFilter = libPixiFilter("blur");
|
|
632
|
-
const desaturateFilter = libPixiFilter("desaturate");
|
|
633
|
-
const contrastFilter = libPixiFilter("contrast", 1.5);
|
|
627
|
+
const brightnessFilter = libPixiFilter("brightness", 1.2); //设置亮度为1.2
|
|
628
|
+
const blurFilter = libPixiFilter("blur"); //设置模糊滤镜
|
|
629
|
+
const desaturateFilter = libPixiFilter("desaturate"); //设置去饱和滤镜
|
|
630
|
+
const contrastFilter = libPixiFilter("contrast", 1.5); //设置对比度为1.5
|
|
634
631
|
```
|
|
635
632
|
|
|
636
633
|
### LibPixiIntervalTrigger-间隔触发
|
|
@@ -640,15 +637,15 @@ const contrastFilter = libPixiFilter("contrast", 1.5); // 设置对比度为1.5
|
|
|
640
637
|
```ts
|
|
641
638
|
const stopInterval = libPixiIntervalTrigger(() => {
|
|
642
639
|
console.log("Triggered interval callback");
|
|
643
|
-
}, [500, 1000]);
|
|
640
|
+
}, [500, 1000]); //随机间隔 500ms 到 1000ms
|
|
644
641
|
|
|
645
642
|
//or
|
|
646
643
|
|
|
647
644
|
const stopInterval = libPixiIntervalTrigger(() => {
|
|
648
645
|
console.log("Triggered interval callback");
|
|
649
|
-
}, 500);
|
|
646
|
+
}, 500); //间隔 500ms
|
|
650
647
|
|
|
651
|
-
|
|
648
|
+
//停止间隔触发
|
|
652
649
|
stopInterval();
|
|
653
650
|
```
|
|
654
651
|
|
|
@@ -661,7 +658,7 @@ const stopOutsideClick = libPixiOutsideClick(container, button, () => {
|
|
|
661
658
|
console.log("Container closed");
|
|
662
659
|
});
|
|
663
660
|
|
|
664
|
-
|
|
661
|
+
//停止监听点击事件
|
|
665
662
|
stopOutsideClick();
|
|
666
663
|
```
|
|
667
664
|
|
|
@@ -670,7 +667,7 @@ stopOutsideClick();
|
|
|
670
667
|
> 为容器创建并应用一个矩形遮罩,用于隐藏溢出的内容,函数会返回遮罩,可控制是否显示遮罩
|
|
671
668
|
|
|
672
669
|
```ts
|
|
673
|
-
const mask = libPixiOverflowHidden(container);
|
|
670
|
+
const mask = libPixiOverflowHidden(container); //为容器创建并应用矩形蒙版
|
|
674
671
|
```
|
|
675
672
|
|
|
676
673
|
### LibPixiPromiseTickerTimeout-TickerPromise 定时器
|
|
@@ -690,7 +687,7 @@ libPixiPromiseTickerTimeout(1000, () => {
|
|
|
690
687
|
> 元素超过指定宽度就缩放
|
|
691
688
|
|
|
692
689
|
```ts
|
|
693
|
-
libPixiScaleContainer(container, 500, 300);
|
|
690
|
+
libPixiScaleContainer(container, 500, 300); //容器超过 500px 宽度或 300px 高度时进行缩放
|
|
694
691
|
```
|
|
695
692
|
|
|
696
693
|
### LibPixiShadow-阴影
|
|
@@ -716,6 +713,6 @@ const stopTimer = libPixiTickerTimeout(() => {
|
|
|
716
713
|
console.log("Callback after delay");
|
|
717
714
|
}, 1000);
|
|
718
715
|
|
|
719
|
-
|
|
716
|
+
//停止定时器
|
|
720
717
|
stopTimer();
|
|
721
718
|
```
|
package/Utils/LibPixiAudio.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "@pixi/sound";
|
|
1
2
|
/** @description 音频播放器
|
|
2
3
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
|
|
3
4
|
*/
|
|
@@ -31,7 +32,7 @@ export declare class LibPixiAudio {
|
|
|
31
32
|
/** @description 停止播放指定音效
|
|
32
33
|
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止
|
|
33
34
|
*/
|
|
34
|
-
stopEffect(
|
|
35
|
+
stopEffect(key: string): void;
|
|
35
36
|
/** @description 设置启用音效
|
|
36
37
|
* @param enabled 启用状态,false为禁用
|
|
37
38
|
*/
|
package/Utils/LibPixiAudio.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import gsap from "gsap";
|
|
11
11
|
import { Assets } from "pixi.js";
|
|
12
|
+
import "@pixi/sound";
|
|
12
13
|
/** @description 音频播放器
|
|
13
14
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
|
|
14
15
|
*/
|
|
@@ -28,11 +29,12 @@ export class LibPixiAudio {
|
|
|
28
29
|
* @param status 播放状态,false为暂停
|
|
29
30
|
*/
|
|
30
31
|
this._setPlayStatus = (status) => {
|
|
32
|
+
var _a, _b;
|
|
31
33
|
if (status) {
|
|
32
|
-
!this._isMusicPaused && this._musicPlayer.play();
|
|
34
|
+
!this._isMusicPaused && ((_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.play());
|
|
33
35
|
}
|
|
34
36
|
else {
|
|
35
|
-
this._musicPlayer.pause();
|
|
37
|
+
(_b = this._musicPlayer) === null || _b === void 0 ? void 0 : _b.pause();
|
|
36
38
|
}
|
|
37
39
|
this._playingList.forEach((item) => {
|
|
38
40
|
if (status) {
|
|
@@ -58,12 +60,6 @@ export class LibPixiAudio {
|
|
|
58
60
|
const id = new Date().getTime();
|
|
59
61
|
const url = Assets.get(key).url;
|
|
60
62
|
const audio = new Audio(url);
|
|
61
|
-
//倒数几秒位置播放
|
|
62
|
-
if (end) {
|
|
63
|
-
const duration = audio.duration;
|
|
64
|
-
const start = duration - end;
|
|
65
|
-
audio.currentTime = Math.max(start, 0);
|
|
66
|
-
}
|
|
67
63
|
audio.muted = this._isBackground || !this.effectEnabled;
|
|
68
64
|
audio.addEventListener("ended", () => {
|
|
69
65
|
this._playingList = this._playingList.filter((item) => item.id !== id);
|
|
@@ -72,6 +68,12 @@ export class LibPixiAudio {
|
|
|
72
68
|
audio
|
|
73
69
|
.play()
|
|
74
70
|
.then(() => {
|
|
71
|
+
//倒数几秒位置播放
|
|
72
|
+
if (end) {
|
|
73
|
+
const duration = audio.duration;
|
|
74
|
+
const start = duration - end;
|
|
75
|
+
audio.currentTime = Math.max(start, 0);
|
|
76
|
+
}
|
|
75
77
|
this._playingList.push({
|
|
76
78
|
id,
|
|
77
79
|
audio,
|
|
@@ -86,6 +88,7 @@ export class LibPixiAudio {
|
|
|
86
88
|
*/
|
|
87
89
|
playMusic(key) {
|
|
88
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
var _a;
|
|
89
92
|
//如果有音乐正在播放,则停止
|
|
90
93
|
if (this._musicPlayer) {
|
|
91
94
|
gsap.killTweensOf(this._musicPlayer);
|
|
@@ -94,7 +97,7 @@ export class LibPixiAudio {
|
|
|
94
97
|
duration: 1,
|
|
95
98
|
ease: "linear",
|
|
96
99
|
});
|
|
97
|
-
this._musicPlayer.pause();
|
|
100
|
+
(_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.pause();
|
|
98
101
|
}
|
|
99
102
|
const url = Assets.get(key).url;
|
|
100
103
|
this._musicPlayer.src = url;
|
|
@@ -121,19 +124,21 @@ export class LibPixiAudio {
|
|
|
121
124
|
}
|
|
122
125
|
/** @description 暂停音乐 */
|
|
123
126
|
pauseMusic() {
|
|
127
|
+
var _a;
|
|
124
128
|
this._isMusicPaused = true;
|
|
125
|
-
this._musicPlayer.pause();
|
|
129
|
+
(_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.pause();
|
|
126
130
|
}
|
|
127
131
|
/** @description 继续播放音乐 */
|
|
128
132
|
resumeMusic() {
|
|
133
|
+
var _a;
|
|
129
134
|
this._isMusicPaused = false;
|
|
130
|
-
this._musicPlayer.play();
|
|
135
|
+
(_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.play();
|
|
131
136
|
}
|
|
132
137
|
/** @description 停止播放指定音效
|
|
133
138
|
* @param key 音效资源Key,内部会使用Assets.get(key)获取音频资源进行停止
|
|
134
139
|
*/
|
|
135
|
-
stopEffect(
|
|
136
|
-
const url = Assets.get(
|
|
140
|
+
stopEffect(key) {
|
|
141
|
+
const url = Assets.get(key).url;
|
|
137
142
|
this._playingList.forEach((item) => {
|
|
138
143
|
if (item.url === url) {
|
|
139
144
|
item.audio.pause();
|