lyb-pixi-js 1.1.19 → 1.2.1

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 CHANGED
@@ -652,12 +652,24 @@ stopInterval();
652
652
  > 点击容器外或入口按钮时隐藏
653
653
 
654
654
  ```ts
655
- const stopOutsideClick = libPixiOutsideClick(container, button, () => {
656
- console.log("Container closed");
657
- });
658
655
 
659
- //停止监听点击事件
660
- stopOutsideClick();
656
+ let removeEventListener: () => void;
657
+ const btn = new Sprite(Assets.get("btnIcon"));
658
+ const optionList = new Container();
659
+ libPixiEvent(btn, "pointertap", () => {
660
+ optionList.visible = !optionList.visible;
661
+
662
+ //列表显示后开始监听是否点击容器外
663
+ if (optionList.visible) {
664
+ removeEventListener = libPixiOutsideClick(optionList, btn, () => {
665
+ optionList.visible = false;
666
+ });
667
+ }
668
+ //如果通过再次点击按钮关闭了列表,则移除监听器
669
+ else {
670
+ removeEventListener();
671
+ }
672
+ });
661
673
  ```
662
674
 
663
675
  ### LibPixiOverflowHidden-溢出裁剪
@@ -1,7 +1,4 @@
1
1
  import "@pixi/sound";
2
- /** @description 音频播放器
3
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
4
- */
5
2
  export declare class LibPixiAudio {
6
3
  /** 是否启用音效 */
7
4
  effectEnabled: boolean;
@@ -12,7 +9,7 @@ export declare class LibPixiAudio {
12
9
  /** 是否已切换后台 */
13
10
  private _isBackground;
14
11
  /** 当前音乐播放器 */
15
- private _musicPlayer;
12
+ private _musicPlayer?;
16
13
  /** 当前正在播放的音效列表 */
17
14
  private _playingList;
18
15
  constructor();
@@ -7,12 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import gsap from "gsap";
11
10
  import { Assets } from "pixi.js";
11
+ import { Howl } from "howler";
12
12
  import "@pixi/sound";
13
- /** @description 音频播放器
14
- * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiAudio-音频播放器
15
- */
16
13
  export class LibPixiAudio {
17
14
  constructor() {
18
15
  /** 是否启用音效 */
@@ -45,7 +42,6 @@ export class LibPixiAudio {
45
42
  }
46
43
  });
47
44
  };
48
- this._musicPlayer = new Audio();
49
45
  document.addEventListener("visibilitychange", () => {
50
46
  this._isBackground = document.hidden;
51
47
  this._setPlayStatus(!document.hidden);
@@ -59,28 +55,26 @@ export class LibPixiAudio {
59
55
  return new Promise((resolve) => {
60
56
  const id = new Date().getTime();
61
57
  const url = Assets.get(key).url;
62
- const audio = new Audio(url);
63
- audio.muted = this._isBackground || !this.effectEnabled;
64
- audio.addEventListener("ended", () => {
58
+ const sound = new Howl({
59
+ src: url,
60
+ mute: this._isBackground || !this.effectEnabled,
61
+ });
62
+ sound.play();
63
+ sound.on("end", () => {
65
64
  this._playingList = this._playingList.filter((item) => item.id !== id);
66
65
  resolve();
67
66
  });
68
- audio
69
- .play()
70
- .then(() => {
71
- //倒数几秒位置播放
72
- if (end) {
73
- const duration = audio.duration;
74
- const start = duration - end;
75
- audio.currentTime = Math.max(start, 0);
76
- }
77
- this._playingList.push({
78
- id,
79
- audio,
80
- url,
81
- });
82
- })
83
- .catch(() => { });
67
+ //倒数几秒位置播放
68
+ if (end) {
69
+ const duration = sound.duration();
70
+ const start = duration - end;
71
+ sound.seek(start);
72
+ }
73
+ this._playingList.push({
74
+ id,
75
+ audio: sound,
76
+ url,
77
+ });
84
78
  });
85
79
  }
86
80
  /** @description 播放音乐
@@ -88,7 +82,7 @@ export class LibPixiAudio {
88
82
  */
89
83
  playMusic(key) {
90
84
  return __awaiter(this, void 0, void 0, function* () {
91
- var _a;
85
+ const url = Assets.get(key).url;
92
86
  //如果有音乐正在播放,则停止
93
87
  if (this._musicPlayer) {
94
88
  gsap.killTweensOf(this._musicPlayer);
@@ -97,29 +91,23 @@ export class LibPixiAudio {
97
91
  duration: 1,
98
92
  ease: "linear",
99
93
  });
100
- (_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.pause();
94
+ this._musicPlayer.stop();
101
95
  }
102
- const url = Assets.get(key).url;
103
- this._musicPlayer.src = url;
104
- this._musicPlayer.loop = true;
105
- this._musicPlayer.volume = 0;
106
- const play = () => {
107
- this._musicPlayer
108
- .play()
109
- .then(() => {
110
- this._isMusicPaused = false;
111
- gsap.killTweensOf(this._musicPlayer);
112
- gsap.to(this._musicPlayer, {
113
- volume: 1,
114
- duration: 1,
115
- ease: "linear",
116
- });
117
- })
118
- .catch(() => {
119
- requestAnimationFrame(play.bind(this));
120
- });
121
- };
122
- play();
96
+ this._musicPlayer = new Howl({
97
+ src: url,
98
+ loop: true,
99
+ volume: 0,
100
+ html5: true,
101
+ mute: this._isBackground || !this.effectEnabled,
102
+ });
103
+ this._musicPlayer.play();
104
+ this._isMusicPaused = false;
105
+ gsap.killTweensOf(this._musicPlayer);
106
+ gsap.to(this._musicPlayer, {
107
+ volume: 1,
108
+ duration: 1,
109
+ ease: "linear",
110
+ });
123
111
  });
124
112
  }
125
113
  /** @description 暂停音乐 */
@@ -164,14 +152,15 @@ export class LibPixiAudio {
164
152
  * @param disabled 静音状态,true为静音
165
153
  */
166
154
  _setMusicMute(disabled) {
167
- this._musicPlayer.muted = disabled || !this.musicEnabled;
155
+ var _a;
156
+ (_a = this._musicPlayer) === null || _a === void 0 ? void 0 : _a.mute(disabled || !this.musicEnabled);
168
157
  }
169
158
  /** @description 设置静音音效
170
159
  * @param disabled 静音状态,true为静音
171
160
  */
172
161
  _setEffectMute(disabled) {
173
162
  this._playingList.forEach((item) => {
174
- item.audio.muted = disabled || !this.effectEnabled;
163
+ item.audio.mute(disabled || !this.effectEnabled);
175
164
  });
176
165
  }
177
166
  }