lyb-pixi-js 1.0.22 → 1.1.0
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 +484 -1
- package/dist/Components/Custom/LibPixiButtonHover/index.d.ts +32 -0
- package/dist/Components/Custom/LibPixiButtonHover/index.js +44 -0
- package/dist/Components/Custom/LibPixiCloseBtn/index.d.ts +14 -0
- package/dist/Components/Custom/LibPixiCloseBtn/index.js +35 -0
- package/dist/Components/Custom/LibPixiDrawer/index.d.ts +16 -0
- package/dist/Components/Custom/LibPixiDrawer/index.js +59 -0
- package/dist/Components/Custom/LibPixiPerforMon/index.d.ts +31 -0
- package/dist/Components/Custom/LibPixiPerforMon/index.js +107 -0
- package/dist/Components/Custom/LibPixiProgress/index.d.ts +29 -0
- package/dist/Components/Custom/LibPixiProgress/index.js +36 -0
- package/dist/Components/Custom/LibPixiScrollContainer/index.d.ts +57 -0
- package/dist/Components/Custom/LibPixiScrollContainer/index.js +166 -0
- package/dist/Components/Custom/LibPixiScrollNum/index.d.ts +62 -0
- package/dist/Components/Custom/LibPixiScrollNum/index.js +146 -0
- package/dist/Components/Custom/LibPixiSlider/index.d.ts +45 -0
- package/dist/Components/Custom/LibPixiSlider/index.js +111 -0
- package/dist/Components/Custom/LibPixiSubAddMinMax/index.d.ts +49 -0
- package/dist/Components/Custom/LibPixiSubAddMinMax/index.js +75 -0
- package/dist/Components/Custom/LibPixiTable/index.d.ts +52 -0
- package/dist/Components/Custom/LibPixiTable/index.js +70 -0
- package/dist/Utils/LibPixiAudio/index.d.ts +34 -0
- package/dist/Utils/LibPixiAudio/index.js +140 -0
- package/dist/Utils/LibPixiCreateNineGrid/index.d.ts +15 -0
- package/dist/Utils/LibPixiCreateNineGrid/index.js +19 -0
- package/dist/Utils/LibPixiEvent/index.d.ts +9 -0
- package/dist/Utils/LibPixiEvent/index.js +22 -0
- package/dist/Utils/LibPixiEventControlled/index.d.ts +8 -0
- package/dist/Utils/LibPixiEventControlled/index.js +21 -0
- package/dist/Utils/LibPixiFilter/index.d.ts +9 -0
- package/dist/Utils/LibPixiFilter/index.js +30 -0
- package/dist/Utils/LibPixiIntervalTrigger/index.d.ts +6 -0
- package/dist/Utils/LibPixiIntervalTrigger/index.js +33 -0
- package/dist/Utils/LibPixiOutsideClick/index.d.ts +8 -0
- package/dist/Utils/LibPixiOutsideClick/index.js +22 -0
- package/dist/Utils/LibPixiOverflowHidden/index.d.ts +6 -0
- package/dist/Utils/LibPixiOverflowHidden/index.js +14 -0
- package/dist/Utils/LibPixiPromiseTickerTimeout/index.d.ts +6 -0
- package/dist/Utils/LibPixiPromiseTickerTimeout/index.js +22 -0
- package/dist/Utils/LibPixiScaleContainer/index.d.ts +8 -0
- package/dist/Utils/LibPixiScaleContainer/index.js +14 -0
- package/dist/Utils/LibPixiShadow/index.d.ts +17 -0
- package/dist/Utils/LibPixiShadow/index.js +18 -0
- package/dist/Utils/LibPixiTickerTimeout/index.d.ts +6 -0
- package/dist/Utils/LibPixiTickerTimeout/index.js +28 -0
- package/dist/libPixiJs.d.ts +155 -25
- package/dist/libPixiJs.js +166 -25
- package/package.json +4 -2
- package/umd/lyb-pixi.js +222 -128
- /package/dist/{Base → Components/Base}/LibPixiBitText/index.d.ts +0 -0
- /package/dist/{Base → Components/Base}/LibPixiBitText/index.js +0 -0
- /package/dist/{Base → Components/Base}/LibPixiContainer/index.d.ts +0 -0
- /package/dist/{Base → Components/Base}/LibPixiContainer/index.js +0 -0
- /package/dist/{Base → Components/Base}/LibPixiParticleMove/index.d.ts +0 -0
- /package/dist/{Base → Components/Base}/LibPixiParticleMove/index.js +0 -0
- /package/dist/{Base → Components/Base}/LibPixiRectBgColor/index.d.ts +0 -0
- /package/dist/{Base → Components/Base}/LibPixiRectBgColor/index.js +0 -0
- /package/dist/{Base → Components/Base}/LibPixiSpine/index.d.ts +0 -0
- /package/dist/{Base → Components/Base}/LibPixiSpine/index.js +0 -0
- /package/dist/{Base → Components/Base}/LibPixiText/index.d.ts +0 -0
- /package/dist/{Base → Components/Base}/LibPixiText/index.js +0 -0
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Lib自用PixiJS
|
|
1
|
+
# Lib自用PixiJS组件&工具方法
|
|
2
2
|
|
|
3
3
|
## 介绍
|
|
4
4
|
|
|
@@ -94,6 +94,26 @@ app.stage.addChild(text);
|
|
|
94
94
|
|
|
95
95
|
\- [LibPixiParticleMove-粒子容器](#LibPixiParticleMove-粒子容器)
|
|
96
96
|
|
|
97
|
+
\- [LibPixiButtonHover-按钮悬浮](#LibPixiButtonHover-按钮悬浮)
|
|
98
|
+
|
|
99
|
+
\- [LibPixiCloseBtn-关闭按钮](#LibPixiCloseBtn-关闭按钮)
|
|
100
|
+
|
|
101
|
+
\- [LibPixiDrawer-抽屉](#LibPixiDrawer-抽屉)
|
|
102
|
+
|
|
103
|
+
\- [LibPixiPerforMon-性能监视器](#LibPixiPerforMon-性能监视器)
|
|
104
|
+
|
|
105
|
+
\- [LibPixiProgress-进度条](#LibPixiProgress-进度条)
|
|
106
|
+
|
|
107
|
+
\- [LibPixiScrollContainer-滚动容器](#LibPixiScrollContainer-滚动容器)
|
|
108
|
+
|
|
109
|
+
\- [LibPixiScrollNum-数字滑动](#LibPixiScrollNum-数字滑动)
|
|
110
|
+
|
|
111
|
+
\- [LibPixiSlider-横向滑动图](#LibPixiSlider-横向滑动图)
|
|
112
|
+
|
|
113
|
+
\- [LibPixiSubAddMinMax-数字控制器](#LibPixiSubAddMinMax-数字控制器)
|
|
114
|
+
|
|
115
|
+
\- [LibPixiTable-数字表格](#LibPixiTable-数字表格)
|
|
116
|
+
|
|
97
117
|
|
|
98
118
|
## Base-基础
|
|
99
119
|
|
|
@@ -204,3 +224,466 @@ const libPixiParticleMove = new LibPixiJs.Base.LibPixiParticleMove({
|
|
|
204
224
|
});
|
|
205
225
|
```
|
|
206
226
|
|
|
227
|
+
## Custom-定制
|
|
228
|
+
|
|
229
|
+
### LibPixiButtonHover-按钮悬浮
|
|
230
|
+
|
|
231
|
+
> 悬浮切换材质
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import { Texture } from "pixi.js";
|
|
235
|
+
import { LibPixiButtonHover } from "./path/to/LibPixiButtonHover";
|
|
236
|
+
|
|
237
|
+
//加载材质资源
|
|
238
|
+
const defaultTexture: Texture = Texture.from("default-icon.png");
|
|
239
|
+
const hoverTexture: Texture = Texture.from("hover-icon.png");
|
|
240
|
+
|
|
241
|
+
//创建按钮实例
|
|
242
|
+
const button = new LibPixiButtonHover({
|
|
243
|
+
texture: defaultTexture,
|
|
244
|
+
hoverTexture: hoverTexture,
|
|
245
|
+
tintColor: "#FF0000", //可选:按钮的初始颜色
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
//设置按钮状态
|
|
249
|
+
button.setDisabled(true); //禁用按钮
|
|
250
|
+
|
|
251
|
+
//在Pixi.js应用的容器中添加按钮
|
|
252
|
+
app.stage.addChild(button);
|
|
253
|
+
|
|
254
|
+
//切换按钮材质
|
|
255
|
+
button.toggleTexture(Texture.from("new-default.png"), Texture.from("new-hover.png"));
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### LibPixiCloseBtn-关闭按钮
|
|
259
|
+
|
|
260
|
+
> 右上角关闭按钮,支持悬浮旋转动画
|
|
261
|
+
|
|
262
|
+
```ts
|
|
263
|
+
import { Sprite, Texture } from "pixi.js";
|
|
264
|
+
import { LibPixiCloseBtn } from "./path/to/LibPixiCloseBtn";
|
|
265
|
+
|
|
266
|
+
//创建按钮材质
|
|
267
|
+
const closeTexture = Texture.from("close-icon.png");
|
|
268
|
+
|
|
269
|
+
//创建按钮精灵
|
|
270
|
+
const closeButton = new Sprite(closeTexture);
|
|
271
|
+
|
|
272
|
+
//创建关闭按钮实例
|
|
273
|
+
const closeBtn = new LibPixiCloseBtn({
|
|
274
|
+
sprite: closeButton,
|
|
275
|
+
onClick: () => {
|
|
276
|
+
console.log("Close button clicked!");
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
//添加到Pixi.js场景
|
|
281
|
+
app.stage.addChild(closeBtn);
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### LibPixiDrawer-抽屉
|
|
285
|
+
|
|
286
|
+
> 底部弹出抽屉
|
|
287
|
+
|
|
288
|
+
```ts
|
|
289
|
+
import { Container } from "pixi.js";
|
|
290
|
+
import { LibPixiDrawer } from "./path/to/LibPixiDrawer";
|
|
291
|
+
|
|
292
|
+
//创建抽屉内容容器
|
|
293
|
+
const drawerContent = new Container();
|
|
294
|
+
//在这里添加你想要的内容,例如一些按钮或文本等
|
|
295
|
+
//drawerContent.addChild(someOtherPixiElement);
|
|
296
|
+
|
|
297
|
+
//创建抽屉实例
|
|
298
|
+
const drawer = new LibPixiDrawer(drawerContent);
|
|
299
|
+
|
|
300
|
+
//添加到Pixi.js场景
|
|
301
|
+
app.stage.addChild(drawer);
|
|
302
|
+
|
|
303
|
+
//关闭抽屉
|
|
304
|
+
//drawer.close();
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### LibPixiPerforMon-性能监视器
|
|
308
|
+
|
|
309
|
+
> 监视帧率、Draw Call、Max Draw Call
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
import { LibPixiPerforMon } from "./path/to/LibPixiPerforMon";
|
|
313
|
+
|
|
314
|
+
//创建性能监视实例
|
|
315
|
+
const perforMon = new LibPixiPerforMon(app);
|
|
316
|
+
|
|
317
|
+
//添加到Pixi应用的舞台
|
|
318
|
+
app.stage.addChild(perforMon);
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### LibPixiProgress-进度条
|
|
322
|
+
|
|
323
|
+
> 通过裁剪的方式显示进度条
|
|
324
|
+
|
|
325
|
+
```ts
|
|
326
|
+
import { Texture } from "pixi.js";
|
|
327
|
+
import { LibPixiProgress } from "./path/to/LibPixiProgress";
|
|
328
|
+
|
|
329
|
+
//创建进度条背景和进度条材质
|
|
330
|
+
const bgTexture = Texture.from("background.png");
|
|
331
|
+
const barTexture = Texture.from("progress-bar.png");
|
|
332
|
+
|
|
333
|
+
//创建进度条实例
|
|
334
|
+
const progress = new LibPixiProgress({
|
|
335
|
+
bgWidth: 400,
|
|
336
|
+
bgHeight: 50,
|
|
337
|
+
barWidth: 400,
|
|
338
|
+
barHeight: 50,
|
|
339
|
+
bgTexture: bgTexture,
|
|
340
|
+
barTexture: barTexture,
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
//设置进度值
|
|
344
|
+
progress.setProgress(0.5); //50% 完成
|
|
345
|
+
|
|
346
|
+
//添加到Pixi.js场景
|
|
347
|
+
app.stage.addChild(progress);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
### LibPixiScrollContainer-滚动容器
|
|
351
|
+
|
|
352
|
+
> 支持鼠标滚轮滚动、鼠标拖动、手指滑动,支持惯性滚动及回弹
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
import { Container } from "pixi.js";
|
|
356
|
+
import { LibPixiScrollContainer } from "./path/to/LibPixiScrollContainer";
|
|
357
|
+
|
|
358
|
+
//创建滚动内容容器
|
|
359
|
+
const scrollContent = new Container();
|
|
360
|
+
//在这里添加滚动内容,例如图片、文本等
|
|
361
|
+
//scrollContent.addChild(someOtherPixiElement);
|
|
362
|
+
|
|
363
|
+
//创建滚动容器实例
|
|
364
|
+
const scrollContainer = new LibPixiScrollContainer({
|
|
365
|
+
width: 800,
|
|
366
|
+
height: 600,
|
|
367
|
+
scrollContent: scrollContent,
|
|
368
|
+
bottomMargin: 50, //可选:底部内边距
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
//添加到Pixi.js场景
|
|
372
|
+
app.stage.addChild(scrollContainer);
|
|
373
|
+
|
|
374
|
+
//设置容器大小
|
|
375
|
+
scrollContainer.setDimensions(800, 600);
|
|
376
|
+
|
|
377
|
+
//将内容添加到滚动容器
|
|
378
|
+
scrollContainer.addContent(new Sprite(Texture.from("new-content.png")));
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
### LibPixiScrollNum-数字滑动
|
|
382
|
+
|
|
383
|
+
> 通过鼠标或手指拖动数字列选择数字
|
|
384
|
+
|
|
385
|
+
```ts
|
|
386
|
+
import { Container } from "pixi.js";
|
|
387
|
+
import { LibPixiScrollNum } from "./path/to/LibPixiScrollNum";
|
|
388
|
+
|
|
389
|
+
//创建滚动内容容器
|
|
390
|
+
const scrollContent = new Container();
|
|
391
|
+
//在这里添加滚动内容,例如数字、文本等
|
|
392
|
+
//scrollContent.addChild(someTextOrSprite);
|
|
393
|
+
|
|
394
|
+
//创建数字选择滚动器
|
|
395
|
+
const scrollNum = new LibPixiScrollNum({
|
|
396
|
+
width: 300,
|
|
397
|
+
height: 600,
|
|
398
|
+
pageHeight: 100,
|
|
399
|
+
content: scrollContent,
|
|
400
|
+
pageNum: 5, //设定总行数
|
|
401
|
+
slideCallback: (index) => {
|
|
402
|
+
console.log("滑动到行:", index);
|
|
403
|
+
},
|
|
404
|
+
scrollCallback: (y, index) => {
|
|
405
|
+
console.log(`当前Y: ${y}, 当前行: ${index}`);
|
|
406
|
+
},
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
//将滚动器添加到场景
|
|
410
|
+
app.stage.addChild(scrollNum);
|
|
411
|
+
|
|
412
|
+
//手动滑动到特定行
|
|
413
|
+
scrollNum.slideTo(2);
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
### LibPixiSlider-横向滑动图
|
|
417
|
+
|
|
418
|
+
> 类似轮播图,但是不会自动轮播
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
import { Container } from "pixi.js";
|
|
422
|
+
import { LibPixiSlider } from "./path/to/LibPixiSlider";
|
|
423
|
+
|
|
424
|
+
//创建滑动内容容器
|
|
425
|
+
const slideContent = new Container();
|
|
426
|
+
//在这里添加幻灯片内容,例如图片、文本等
|
|
427
|
+
//slideContent.addChild(someImageOrText);
|
|
428
|
+
|
|
429
|
+
//创建幻灯片
|
|
430
|
+
const slider = new LibPixiSlider(
|
|
431
|
+
400, //宽度
|
|
432
|
+
300, //高度
|
|
433
|
+
slideContent,
|
|
434
|
+
(pageIndex, pageNum) => {
|
|
435
|
+
console.log(`当前页: ${pageIndex + 1} / ${pageNum + 1}`);
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
//将幻灯片添加到场景
|
|
440
|
+
app.stage.addChild(slider);
|
|
441
|
+
|
|
442
|
+
//手动滑动到上一页或下一页
|
|
443
|
+
slider.prev();
|
|
444
|
+
slider.next();
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### LibPixiSubAddMinMax-数字控制器
|
|
448
|
+
|
|
449
|
+
> 最小、最大按钮和增减按钮功能及置灰逻辑
|
|
450
|
+
|
|
451
|
+
```ts
|
|
452
|
+
import { LibPixiSubAddMinMax } from "./path/to/LibPixiSubAddMinMax";
|
|
453
|
+
import { Container } from "pixi.js";
|
|
454
|
+
|
|
455
|
+
//创建最小、最大、增加和减少按钮
|
|
456
|
+
const minBtn = new Container();
|
|
457
|
+
const maxBtn = new Container();
|
|
458
|
+
const subBtn = new Container();
|
|
459
|
+
const addBtn = new Container();
|
|
460
|
+
|
|
461
|
+
//设置初始下注索引和金额列表数量
|
|
462
|
+
const initialBetIndex = 0;
|
|
463
|
+
const betAmountListLength = 5;
|
|
464
|
+
|
|
465
|
+
//金额更新回调
|
|
466
|
+
const onAmountIndex = (index: number) => {
|
|
467
|
+
console.log(`当前金额索引: ${index}`);
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
//创建LibPixiSubAddMinMax实例
|
|
471
|
+
const betAmountController = new LibPixiSubAddMinMax({
|
|
472
|
+
minBtn,
|
|
473
|
+
maxBtn,
|
|
474
|
+
subBtn,
|
|
475
|
+
addBtn,
|
|
476
|
+
initialBetIndex,
|
|
477
|
+
betAmountListLength,
|
|
478
|
+
onAmountIndex,
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
//绑定按钮事件
|
|
482
|
+
minBtn.on("pointerdown", () => betAmountController.min());
|
|
483
|
+
maxBtn.on("pointerdown", () => betAmountController.max());
|
|
484
|
+
subBtn.on("pointerdown", () => betAmountController.sub());
|
|
485
|
+
addBtn.on("pointerdown", () => betAmountController.add());
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
### LibPixiTable-数字表格
|
|
489
|
+
|
|
490
|
+
> 绘制表格并填充数字
|
|
491
|
+
|
|
492
|
+
```ts
|
|
493
|
+
import { LibPixiTable } from "./path/to/LibPixiTable";
|
|
494
|
+
import { Container } from "pixi.js";
|
|
495
|
+
|
|
496
|
+
//定义表格数据
|
|
497
|
+
const data: (number | string)[][] = [
|
|
498
|
+
[1, 2, 3],
|
|
499
|
+
[4, 5, 6],
|
|
500
|
+
[7, 8, 9],
|
|
501
|
+
];
|
|
502
|
+
|
|
503
|
+
//创建LibPixiTable实例
|
|
504
|
+
const table = new LibPixiTable({
|
|
505
|
+
data,
|
|
506
|
+
cellWidth: 130,
|
|
507
|
+
cellHeight: 100,
|
|
508
|
+
fontSize: 24,
|
|
509
|
+
fontColor: "#B4B4B8",
|
|
510
|
+
lineWidth: 3,
|
|
511
|
+
lineColor: "#B4B4B8",
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
//将表格添加到舞台
|
|
515
|
+
stage.addChild(table);
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
## Utils-工具方法
|
|
519
|
+
|
|
520
|
+
### LibPixiAudio-音频播放器
|
|
521
|
+
|
|
522
|
+
> 音频播放器
|
|
523
|
+
|
|
524
|
+
```ts
|
|
525
|
+
const audioPlayer = new LibPixiAudio();
|
|
526
|
+
|
|
527
|
+
// 播放音效
|
|
528
|
+
audioPlayer.playEffect('effect-link')
|
|
529
|
+
.then(() => {
|
|
530
|
+
console.log('音效播放完成');
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
// 播放音乐
|
|
534
|
+
audioPlayer.playMusic('music-link');
|
|
535
|
+
|
|
536
|
+
// 暂停音乐
|
|
537
|
+
audioPlayer.pauseMusic();
|
|
538
|
+
|
|
539
|
+
// 继续播放音乐
|
|
540
|
+
audioPlayer.resumeMusic();
|
|
541
|
+
|
|
542
|
+
// 停止指定音效
|
|
543
|
+
audioPlayer.stopEffect('effect-link');
|
|
544
|
+
|
|
545
|
+
// 设置启用音效
|
|
546
|
+
audioPlayer.setEffectEnabled(false);
|
|
547
|
+
|
|
548
|
+
// 设置启用音乐
|
|
549
|
+
audioPlayer.setMusicEnabled(false);
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
### LibPixiCreateNineGrid-九宫格图
|
|
553
|
+
|
|
554
|
+
> 九宫格图
|
|
555
|
+
|
|
556
|
+
```ts
|
|
557
|
+
const nineGrid = libPixiCreateNineGrid({
|
|
558
|
+
texture: yourTexture, // 传入纹理
|
|
559
|
+
dotWidth: 10, // 四个角的宽度,可以是数字或者数组
|
|
560
|
+
width: 200, // 宽度
|
|
561
|
+
height: 150, // 高度
|
|
562
|
+
});
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
### LibPixiEvent-事件注册
|
|
566
|
+
|
|
567
|
+
> 事件注册
|
|
568
|
+
|
|
569
|
+
```ts
|
|
570
|
+
libPixiEvent(container, 'pointerdown', (e) => {
|
|
571
|
+
console.log('Pointer down event triggered', e);
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// 只执行一次的事件
|
|
575
|
+
libPixiEvent(container, 'pointerup', (e) => {
|
|
576
|
+
console.log('Pointer up event triggered', e);
|
|
577
|
+
}, true);
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
### LibPixiEventControlled-可关闭的事件
|
|
581
|
+
|
|
582
|
+
> 设置可关闭的事件监听,调用自身后不再触发
|
|
583
|
+
|
|
584
|
+
```ts
|
|
585
|
+
const closeEvent = libPixiEventControlled(container, 'pointerdown', (e) => {
|
|
586
|
+
console.log('Pointer down event triggered', e);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
// 调用返回的函数关闭事件监听
|
|
590
|
+
closeEvent();
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
### LibPixiFilter-滤镜
|
|
594
|
+
|
|
595
|
+
> 滤镜
|
|
596
|
+
|
|
597
|
+
```ts
|
|
598
|
+
const brightnessFilter = libPixiFilter('brightness', 1.2); // 设置亮度为1.2
|
|
599
|
+
const blurFilter = libPixiFilter('blur'); // 设置模糊滤镜
|
|
600
|
+
const desaturateFilter = libPixiFilter('desaturate'); // 设置去饱和滤镜
|
|
601
|
+
const contrastFilter = libPixiFilter('contrast', 1.5); // 设置对比度为1.5
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
### LibPixiIntervalTrigger-间隔触发
|
|
605
|
+
|
|
606
|
+
> 间隔触发
|
|
607
|
+
|
|
608
|
+
```ts
|
|
609
|
+
const stopInterval = libPixiIntervalTrigger(() => {
|
|
610
|
+
console.log('Triggered interval callback');
|
|
611
|
+
}, [500, 1000]); // 随机间隔 500ms 到 1000ms
|
|
612
|
+
|
|
613
|
+
//or
|
|
614
|
+
|
|
615
|
+
const stopInterval = libPixiIntervalTrigger(() => {
|
|
616
|
+
console.log('Triggered interval callback');
|
|
617
|
+
}, 500); // 间隔 500ms
|
|
618
|
+
|
|
619
|
+
// 停止间隔触发
|
|
620
|
+
stopInterval();
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
### LibPixiOutsideClick-失焦隐藏
|
|
624
|
+
|
|
625
|
+
> 点击容器外或入口按钮时隐藏
|
|
626
|
+
|
|
627
|
+
```ts
|
|
628
|
+
const stopOutsideClick = libPixiOutsideClick(container, button, () => {
|
|
629
|
+
console.log('Container closed');
|
|
630
|
+
});
|
|
631
|
+
|
|
632
|
+
// 停止监听点击事件
|
|
633
|
+
stopOutsideClick();
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
### LibPixiOverflowHidden-溢出裁剪
|
|
637
|
+
|
|
638
|
+
> 为容器创建并应用一个矩形遮罩,用于隐藏溢出的内容,函数会返回遮罩,可控制是否显示遮罩
|
|
639
|
+
|
|
640
|
+
```ts
|
|
641
|
+
const mask = libPixiOverflowHidden(container); // 为容器创建并应用矩形蒙版
|
|
642
|
+
```
|
|
643
|
+
|
|
644
|
+
### LibPixiPromiseTickerTimeout-TickerPromise定时器
|
|
645
|
+
|
|
646
|
+
> 基于 Ticker 和 Promise 的定时器
|
|
647
|
+
|
|
648
|
+
```ts
|
|
649
|
+
libPixiPromiseTickerTimeout(1000, () => {
|
|
650
|
+
console.log('Callback after 1000ms');
|
|
651
|
+
}).then(() => {
|
|
652
|
+
console.log('Timer completed');
|
|
653
|
+
});
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
### LibPixiScaleContainer-超出缩放
|
|
657
|
+
|
|
658
|
+
> 元素超过指定宽度就缩放
|
|
659
|
+
|
|
660
|
+
```ts
|
|
661
|
+
libPixiScaleContainer(container, 500, 300); // 容器超过 500px 宽度或 300px 高度时进行缩放
|
|
662
|
+
```
|
|
663
|
+
|
|
664
|
+
### LibPixiShadow-阴影
|
|
665
|
+
|
|
666
|
+
> 为图片或容器设置阴影
|
|
667
|
+
|
|
668
|
+
```ts
|
|
669
|
+
libPixiShadow(container, {
|
|
670
|
+
color: "#ff0000",
|
|
671
|
+
alpha: 0.5,
|
|
672
|
+
blur: 5,
|
|
673
|
+
distance: 10,
|
|
674
|
+
offset: { x: 2, y: 2 },
|
|
675
|
+
});
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
### LibPixiTickerTimeout-Ticker定时器
|
|
679
|
+
|
|
680
|
+
> 基于 Ticker 的定时器
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
const stopTimer = libPixiTickerTimeout(() => {
|
|
684
|
+
console.log('Callback after delay');
|
|
685
|
+
}, 1000);
|
|
686
|
+
|
|
687
|
+
// 停止定时器
|
|
688
|
+
stopTimer();
|
|
689
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Container, type Texture } from "pixi.js";
|
|
2
|
+
export interface LibPixiButtonHoverParams {
|
|
3
|
+
/** 图标资源 */
|
|
4
|
+
texture: Texture;
|
|
5
|
+
/** 悬浮图标 */
|
|
6
|
+
hoverTexture: Texture;
|
|
7
|
+
/** 染色 */
|
|
8
|
+
tintColor?: string;
|
|
9
|
+
}
|
|
10
|
+
/** @description 悬浮切换材质
|
|
11
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiButtonHover-按钮悬浮
|
|
12
|
+
*/
|
|
13
|
+
export declare class LibPixiButtonHover extends Container {
|
|
14
|
+
/** 按钮 */
|
|
15
|
+
private _btn;
|
|
16
|
+
/** 默认材质 */
|
|
17
|
+
private _texture;
|
|
18
|
+
/** 悬浮材质 */
|
|
19
|
+
private _hoverTexture;
|
|
20
|
+
/** 染色 */
|
|
21
|
+
private _tintColor?;
|
|
22
|
+
constructor(params: LibPixiButtonHoverParams);
|
|
23
|
+
/** @description 切换材质
|
|
24
|
+
* @param texture 默认材质
|
|
25
|
+
* @param hoverTexture 悬浮材质
|
|
26
|
+
*/
|
|
27
|
+
toggleTexture(texture: Texture, hoverTexture: Texture): void;
|
|
28
|
+
/** @description 屏蔽
|
|
29
|
+
* @param status 状态
|
|
30
|
+
*/
|
|
31
|
+
setDisabled(status: boolean): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Container, Sprite } from "pixi.js";
|
|
2
|
+
import { libPixiEvent } from "../../../Utils/LibPixiEvent";
|
|
3
|
+
/** @description 悬浮切换材质
|
|
4
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiButtonHover-按钮悬浮
|
|
5
|
+
*/
|
|
6
|
+
export class LibPixiButtonHover extends Container {
|
|
7
|
+
constructor(params) {
|
|
8
|
+
super();
|
|
9
|
+
const { texture, hoverTexture, tintColor } = params;
|
|
10
|
+
this._texture = texture;
|
|
11
|
+
this._hoverTexture = hoverTexture;
|
|
12
|
+
this._tintColor = tintColor;
|
|
13
|
+
//创建图标容器
|
|
14
|
+
const iconBox = new Container();
|
|
15
|
+
this.addChild(iconBox);
|
|
16
|
+
//创建图标
|
|
17
|
+
this._btn = new Sprite(texture);
|
|
18
|
+
iconBox.addChild(this._btn);
|
|
19
|
+
tintColor && (this._btn.tint = tintColor);
|
|
20
|
+
libPixiEvent(iconBox, "pointerenter", () => {
|
|
21
|
+
this._btn._texture = this._hoverTexture;
|
|
22
|
+
this._btn.tint = "#fff";
|
|
23
|
+
});
|
|
24
|
+
libPixiEvent(iconBox, "pointerleave", () => {
|
|
25
|
+
this._btn._texture = this._texture;
|
|
26
|
+
tintColor && (this._btn.tint = tintColor);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/** @description 切换材质
|
|
30
|
+
* @param texture 默认材质
|
|
31
|
+
* @param hoverTexture 悬浮材质
|
|
32
|
+
*/
|
|
33
|
+
toggleTexture(texture, hoverTexture) {
|
|
34
|
+
this._texture = texture;
|
|
35
|
+
this._hoverTexture = hoverTexture;
|
|
36
|
+
this._btn._texture = hoverTexture;
|
|
37
|
+
}
|
|
38
|
+
/** @description 屏蔽
|
|
39
|
+
* @param status 状态
|
|
40
|
+
*/
|
|
41
|
+
setDisabled(status) {
|
|
42
|
+
this._btn.tint = status ? "#7C7C7C" : this._tintColor || "#fff";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LibPixiContainer } from "../../Base/LibPixiContainer";
|
|
2
|
+
import type { Sprite } from "pixi.js";
|
|
3
|
+
export interface LibPixiCloseBtnParams {
|
|
4
|
+
/** 按钮素材 */
|
|
5
|
+
sprite: Sprite;
|
|
6
|
+
/** 点击回调 */
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
}
|
|
9
|
+
/** @description 右上角关闭按钮,支持悬浮旋转动画
|
|
10
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiCloseBtn-关闭按钮
|
|
11
|
+
*/
|
|
12
|
+
export declare class LibPixiCloseBtn extends LibPixiContainer {
|
|
13
|
+
constructor(params: LibPixiCloseBtnParams);
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import gsap from "gsap";
|
|
2
|
+
import { LibPixiContainer } from "../../Base/LibPixiContainer";
|
|
3
|
+
import { libPixiEvent } from "../../../Utils/LibPixiEvent";
|
|
4
|
+
/** @description 右上角关闭按钮,支持悬浮旋转动画
|
|
5
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiCloseBtn-关闭按钮
|
|
6
|
+
*/
|
|
7
|
+
export class LibPixiCloseBtn extends LibPixiContainer {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
const { sprite, onClick } = params;
|
|
10
|
+
super(sprite.width, sprite.height);
|
|
11
|
+
this.addChild(sprite);
|
|
12
|
+
sprite.anchor.set(0.5);
|
|
13
|
+
sprite.x = sprite.width / 2;
|
|
14
|
+
sprite.y = sprite.height / 2;
|
|
15
|
+
libPixiEvent(this, "pointerenter", () => {
|
|
16
|
+
gsap.to(sprite, {
|
|
17
|
+
duration: 0.25,
|
|
18
|
+
rotation: 180 * (Math.PI / 180),
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
libPixiEvent(this, "pointerleave", () => {
|
|
22
|
+
sprite.alpha = 1;
|
|
23
|
+
gsap.to(sprite, {
|
|
24
|
+
duration: 0.25,
|
|
25
|
+
rotation: 0,
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
libPixiEvent(this, "pointerdown", () => {
|
|
29
|
+
sprite.alpha = 0.5;
|
|
30
|
+
});
|
|
31
|
+
libPixiEvent(this, "pointerup", () => {
|
|
32
|
+
onClick();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Container } from "pixi.js";
|
|
2
|
+
/** @description 底部弹出抽屉
|
|
3
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiDrawer-抽屉
|
|
4
|
+
*/
|
|
5
|
+
export declare class LibPixiDrawer extends Container {
|
|
6
|
+
/** 蒙版UI */
|
|
7
|
+
private _maskUI;
|
|
8
|
+
/** 抽屉容器 */
|
|
9
|
+
private _drawerContainer;
|
|
10
|
+
/**
|
|
11
|
+
* @param content 抽屉内容
|
|
12
|
+
*/
|
|
13
|
+
constructor(content: Container);
|
|
14
|
+
/** @description 关闭 */
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Container } from "pixi.js";
|
|
11
|
+
import gsap from "gsap";
|
|
12
|
+
import { LibPixiRectBgColor } from "../../Base/LibPixiRectBgColor";
|
|
13
|
+
/** @description 底部弹出抽屉
|
|
14
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiDrawer-抽屉
|
|
15
|
+
*/
|
|
16
|
+
export class LibPixiDrawer extends Container {
|
|
17
|
+
/**
|
|
18
|
+
* @param content 抽屉内容
|
|
19
|
+
*/
|
|
20
|
+
constructor(content) {
|
|
21
|
+
super();
|
|
22
|
+
//蒙版
|
|
23
|
+
this._maskUI = new LibPixiRectBgColor({
|
|
24
|
+
bgColor: "#000",
|
|
25
|
+
width: 1080,
|
|
26
|
+
height: 1920,
|
|
27
|
+
});
|
|
28
|
+
this.addChild(this._maskUI);
|
|
29
|
+
this._maskUI.alpha = 0;
|
|
30
|
+
this._maskUI.eventMode = "static";
|
|
31
|
+
//弹窗内容容器
|
|
32
|
+
this._drawerContainer = content;
|
|
33
|
+
this.addChild(this._drawerContainer);
|
|
34
|
+
this._drawerContainer.y = this._maskUI.height;
|
|
35
|
+
gsap.to(this._maskUI, {
|
|
36
|
+
duration: 0.25,
|
|
37
|
+
alpha: 0.5,
|
|
38
|
+
});
|
|
39
|
+
gsap.to(this._drawerContainer, {
|
|
40
|
+
duration: 0.25,
|
|
41
|
+
ease: "power1.out",
|
|
42
|
+
y: this._maskUI.height - this._drawerContainer.height,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/** @description 关闭 */
|
|
46
|
+
close() {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
gsap.to(this._drawerContainer, {
|
|
49
|
+
duration: 0.25,
|
|
50
|
+
y: this._maskUI.height,
|
|
51
|
+
});
|
|
52
|
+
yield gsap.to(this._maskUI, {
|
|
53
|
+
duration: 0.25,
|
|
54
|
+
delay: 0.125,
|
|
55
|
+
alpha: 0,
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|