lyb-pixi-js 1.6.2 → 1.7.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/Components/Base/LibPixiParticleMove.d.ts +64 -2
- package/Components/Base/LibPixiParticleMove.js +50 -13
- package/Components/Base/LibPixiRectBgColor.d.ts +2 -6
- package/Components/Base/LibPixiRectBgColor.js +1 -3
- package/Components/Custom/LibPixiSlider.d.ts +4 -0
- package/Components/Custom/LibPixiSlider.js +34 -36
- package/README.md +223 -23
- package/Utils/LibPixiEvent.d.ts +1 -0
- package/Utils/LibPixiEvent.js +1 -0
- package/lyb-pixi.js +54698 -1137
- package/package.json +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Container } from "pixi.js";
|
|
2
|
-
import { type EmitterConfigV3 } from "@pixi/particle-emitter";
|
|
3
2
|
export interface LibPixiParticleMoveParams {
|
|
4
3
|
/** 粒子JSON资源 */
|
|
5
|
-
|
|
4
|
+
container: Container;
|
|
6
5
|
/** 运动时长 */
|
|
7
6
|
duration: number;
|
|
8
7
|
/** 粒子开始位置 */
|
|
@@ -26,6 +25,66 @@ export interface LibPixiParticleMoveParams {
|
|
|
26
25
|
showControl?: boolean;
|
|
27
26
|
/** 是否循环,调试使用 */
|
|
28
27
|
loop?: boolean;
|
|
28
|
+
/** 是否启用粒子容器 */
|
|
29
|
+
enableParticleContainer?: boolean;
|
|
30
|
+
/** 粒子配置 */
|
|
31
|
+
particleConfig: {
|
|
32
|
+
/** 随机时长 */
|
|
33
|
+
lifetime: {
|
|
34
|
+
/** 最小时长 */
|
|
35
|
+
min: number;
|
|
36
|
+
/** 最大时长 */
|
|
37
|
+
max: number;
|
|
38
|
+
};
|
|
39
|
+
/** 混合模式 */
|
|
40
|
+
blendMode?: string;
|
|
41
|
+
/** 频率,秒/个 */
|
|
42
|
+
frequency?: number;
|
|
43
|
+
/** 透明度变化 */
|
|
44
|
+
alpha?: {
|
|
45
|
+
/** 开始透明度 */
|
|
46
|
+
start: number;
|
|
47
|
+
/** 结束透明度 */
|
|
48
|
+
end: number;
|
|
49
|
+
};
|
|
50
|
+
/** 颜色变化 */
|
|
51
|
+
color?: {
|
|
52
|
+
/** 开始颜色 */
|
|
53
|
+
start: string;
|
|
54
|
+
/** 结束颜色 */
|
|
55
|
+
end: string;
|
|
56
|
+
};
|
|
57
|
+
/** 随机缩放变化 */
|
|
58
|
+
scale?: {
|
|
59
|
+
/** 最小 */
|
|
60
|
+
start: number;
|
|
61
|
+
/** 最大 */
|
|
62
|
+
end: number;
|
|
63
|
+
};
|
|
64
|
+
/** 随机偏移角度变化 */
|
|
65
|
+
rotation?: {
|
|
66
|
+
/** 最小角度 */
|
|
67
|
+
min: number;
|
|
68
|
+
/** 最大角度 */
|
|
69
|
+
max: number;
|
|
70
|
+
};
|
|
71
|
+
/** 随机自身旋转角度变化 */
|
|
72
|
+
rotate?: {
|
|
73
|
+
/** 最小角度 */
|
|
74
|
+
min: number;
|
|
75
|
+
/** 最大角度 */
|
|
76
|
+
max: number;
|
|
77
|
+
};
|
|
78
|
+
/** 移动速度,像素 */
|
|
79
|
+
speed?: {
|
|
80
|
+
/** 开始速度,不能为0,可无限接近0 */
|
|
81
|
+
start: number;
|
|
82
|
+
/** 结束速度,开始速度会衰减到结束速度 */
|
|
83
|
+
end: number;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
/** 头部粒子到达终点后触发,可在此设置隐藏动画,隐藏动画结束后调用 destroy 参数进行销毁 */
|
|
87
|
+
onDestroy?: (destroy: () => void) => void;
|
|
29
88
|
}
|
|
30
89
|
/** @description 利用贝塞尔曲线实现粒子移动
|
|
31
90
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiParticleMove-粒子容器
|
|
@@ -33,7 +92,10 @@ export interface LibPixiParticleMoveParams {
|
|
|
33
92
|
export declare class LibPixiParticleMove extends Container {
|
|
34
93
|
private _particleContainer;
|
|
35
94
|
constructor(params: LibPixiParticleMoveParams);
|
|
95
|
+
/** @description 创建贝塞尔曲线路径点组 */
|
|
36
96
|
private _createBezierPoints;
|
|
97
|
+
/** @description 计算贝塞尔曲线单个路径衔接点 */
|
|
37
98
|
private _multiPointBezier;
|
|
99
|
+
/** @description 计算组合数 */
|
|
38
100
|
private _binomial;
|
|
39
101
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Container, ParticleContainer, Ticker } from "pixi.js";
|
|
2
|
-
import { Emitter } from "@pixi/particle-emitter";
|
|
2
|
+
import { Emitter, upgradeConfig } from "@pixi/particle-emitter";
|
|
3
3
|
import gsap from "gsap";
|
|
4
4
|
import { LibPixiText } from "./LibPixiText";
|
|
5
5
|
/** @description 利用贝塞尔曲线实现粒子移动
|
|
@@ -8,11 +8,32 @@ import { LibPixiText } from "./LibPixiText";
|
|
|
8
8
|
export class LibPixiParticleMove extends Container {
|
|
9
9
|
constructor(params) {
|
|
10
10
|
super();
|
|
11
|
-
const { start, control, end,
|
|
12
|
-
|
|
11
|
+
const { start, control, end, container, duration, ease = "power1.out", showControl = false, loop = false, enableParticleContainer = false, particleConfig, onDestroy, } = params;
|
|
12
|
+
const config = upgradeConfig({
|
|
13
|
+
lifetime: particleConfig.lifetime,
|
|
14
|
+
blendMode: particleConfig.blendMode,
|
|
15
|
+
frequency: particleConfig.frequency || 0.01,
|
|
16
|
+
maxParticles: 1 / (particleConfig.frequency || 0.01),
|
|
17
|
+
alpha: particleConfig.alpha,
|
|
18
|
+
scale: particleConfig.scale,
|
|
19
|
+
color: particleConfig.color,
|
|
20
|
+
startRotation: particleConfig.rotation,
|
|
21
|
+
rotationSpeed: particleConfig.rotate,
|
|
22
|
+
speed: particleConfig.speed,
|
|
23
|
+
pos: {
|
|
24
|
+
x: 0,
|
|
25
|
+
y: 0,
|
|
26
|
+
},
|
|
27
|
+
}, [container]);
|
|
28
|
+
if (enableParticleContainer) {
|
|
29
|
+
this._particleContainer = new ParticleContainer();
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this._particleContainer = new Container();
|
|
33
|
+
}
|
|
13
34
|
this.addChild(this._particleContainer);
|
|
14
35
|
// 初始化粒子发射器
|
|
15
|
-
const flyParticle = new Emitter(this._particleContainer,
|
|
36
|
+
const flyParticle = new Emitter(this._particleContainer, config);
|
|
16
37
|
// 创建贝塞尔曲线的路径
|
|
17
38
|
const path = this._createBezierPoints([start, ...control, end], 100, showControl);
|
|
18
39
|
// 用来控制路径动画的对象
|
|
@@ -21,6 +42,7 @@ export class LibPixiParticleMove extends Container {
|
|
|
21
42
|
duration,
|
|
22
43
|
pathThrough: path.length - 1,
|
|
23
44
|
repeat: loop ? -1 : 0,
|
|
45
|
+
repeatDelay: loop ? 1 : 0,
|
|
24
46
|
ease,
|
|
25
47
|
onStart: () => {
|
|
26
48
|
flyParticle.emit = true;
|
|
@@ -31,23 +53,33 @@ export class LibPixiParticleMove extends Container {
|
|
|
31
53
|
flyParticle.updateOwnerPos(p.x, p.y);
|
|
32
54
|
},
|
|
33
55
|
onComplete: () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
duration: 0.5,
|
|
37
|
-
onComplete: () => {
|
|
56
|
+
if (onDestroy) {
|
|
57
|
+
onDestroy(() => {
|
|
38
58
|
flyParticle.emit = false;
|
|
39
59
|
ticker.destroy();
|
|
40
|
-
this.
|
|
41
|
-
}
|
|
42
|
-
}
|
|
60
|
+
this.destroy({ children: true });
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
gsap.to(this, {
|
|
65
|
+
alpha: 0,
|
|
66
|
+
duration: 1,
|
|
67
|
+
onComplete: () => {
|
|
68
|
+
flyParticle.emit = false;
|
|
69
|
+
ticker.destroy();
|
|
70
|
+
this.destroy({ children: true });
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
43
74
|
},
|
|
44
75
|
});
|
|
45
76
|
const ticker = new Ticker();
|
|
46
77
|
ticker.add(() => {
|
|
47
|
-
flyParticle.update(
|
|
78
|
+
flyParticle.update(ticker.deltaMS / 1000);
|
|
48
79
|
});
|
|
49
80
|
ticker.start();
|
|
50
81
|
}
|
|
82
|
+
/** @description 创建贝塞尔曲线路径点组 */
|
|
51
83
|
_createBezierPoints(anchorPoints, pointsAmount, showControl) {
|
|
52
84
|
const points = [];
|
|
53
85
|
// 渲染控制点
|
|
@@ -56,7 +88,10 @@ export class LibPixiParticleMove extends Container {
|
|
|
56
88
|
//创建一个小圆点
|
|
57
89
|
const text = new LibPixiText({
|
|
58
90
|
text: index + 1,
|
|
59
|
-
fontSize:
|
|
91
|
+
fontSize: 20,
|
|
92
|
+
stroke: true,
|
|
93
|
+
strokeColor: "#000",
|
|
94
|
+
strokeThickness: 1,
|
|
60
95
|
});
|
|
61
96
|
text.position.set(item.x, item.y);
|
|
62
97
|
this.addChild(text);
|
|
@@ -69,6 +104,7 @@ export class LibPixiParticleMove extends Container {
|
|
|
69
104
|
}
|
|
70
105
|
return points;
|
|
71
106
|
}
|
|
107
|
+
/** @description 计算贝塞尔曲线单个路径衔接点 */
|
|
72
108
|
_multiPointBezier(points, t) {
|
|
73
109
|
const len = points.length;
|
|
74
110
|
let x = 0, y = 0;
|
|
@@ -88,6 +124,7 @@ export class LibPixiParticleMove extends Container {
|
|
|
88
124
|
}
|
|
89
125
|
return { x, y };
|
|
90
126
|
}
|
|
127
|
+
/** @description 计算组合数 */
|
|
91
128
|
_binomial(n, k) {
|
|
92
129
|
if (k === 0 || k === n)
|
|
93
130
|
return 1;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { Graphics } from "pixi.js";
|
|
2
2
|
export interface LibPixiRectBgColorParams {
|
|
3
3
|
/** 宽度 */
|
|
4
|
-
width
|
|
4
|
+
width: number;
|
|
5
5
|
/** 高度 */
|
|
6
|
-
height
|
|
6
|
+
height: number;
|
|
7
7
|
/** 背景颜色 */
|
|
8
8
|
bgColor?: string | number;
|
|
9
|
-
/** x轴偏移 */
|
|
10
|
-
x?: number;
|
|
11
|
-
/** y轴偏移 */
|
|
12
|
-
y?: number;
|
|
13
9
|
/** 透明度 */
|
|
14
10
|
alpha?: number;
|
|
15
11
|
/** 圆角半径 */
|
|
@@ -18,9 +18,7 @@ export class LibPixiRectBgColor extends Graphics {
|
|
|
18
18
|
this.borderColor = "black";
|
|
19
19
|
/** 背景色 */
|
|
20
20
|
this.bgAlpha = 1;
|
|
21
|
-
const {
|
|
22
|
-
this.x = x;
|
|
23
|
-
this.y = y;
|
|
21
|
+
const { width, height, bgColor = "#fff", alpha = 1, radius = 0, borderWidth = 0, borderColor = "black", enableTint = true, } = options;
|
|
24
22
|
this.bgAlpha = alpha;
|
|
25
23
|
this.radius = radius;
|
|
26
24
|
this.enableTint = enableTint;
|
|
@@ -7,6 +7,8 @@ interface LibPixiSliderParams {
|
|
|
7
7
|
height: number;
|
|
8
8
|
/** 滑动页列表 */
|
|
9
9
|
slideList: Container[];
|
|
10
|
+
/** 是否启用循环滑动 */
|
|
11
|
+
loop?: boolean;
|
|
10
12
|
/** 是否启用景深 */
|
|
11
13
|
enableDepth?: boolean;
|
|
12
14
|
/** 景深透明度 */
|
|
@@ -26,6 +28,8 @@ export declare class LibPixiSlider extends LibPixiContainer {
|
|
|
26
28
|
private _slideWidth;
|
|
27
29
|
/** 滑动区域高度 */
|
|
28
30
|
private _slideHeight;
|
|
31
|
+
/** 是否启用循环 */
|
|
32
|
+
private _loop;
|
|
29
33
|
/** 记录拖动开始时的X坐标 */
|
|
30
34
|
private _startX;
|
|
31
35
|
/** 偏移量 */
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Container } from "pixi.js";
|
|
2
2
|
import gsap from "gsap";
|
|
3
|
+
import { LibJsLerp } from "lyb-js/Math/LibJsLerp.js";
|
|
3
4
|
import { libPixiOverflowHidden } from "../../Utils/LibPixiOverflowHidden";
|
|
4
5
|
import { LibPixiContainer } from "../Base/LibPixiContainer";
|
|
5
|
-
import {
|
|
6
|
+
import { libPixiEvent } from "../../Utils/LibPixiEvent";
|
|
6
7
|
/** @description 类似轮播图,但是不会自动轮播
|
|
7
8
|
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSlider-横向滑动图
|
|
8
9
|
*/
|
|
@@ -14,7 +15,7 @@ export class LibPixiSlider extends LibPixiContainer {
|
|
|
14
15
|
* @param slideCallback 滑动结束回调
|
|
15
16
|
*/
|
|
16
17
|
constructor(params) {
|
|
17
|
-
const { width, height, slideList, slideCallback, enableDepth = false, depthAlpha = 0.5, depthScale = 0.5, } = params;
|
|
18
|
+
const { width, height, slideList, slideCallback, loop = false, enableDepth = false, depthAlpha = 0.5, depthScale = 0.5, } = params;
|
|
18
19
|
super(width, height);
|
|
19
20
|
/** 当前幻灯片索引 */
|
|
20
21
|
this._currentIndex = 0;
|
|
@@ -22,6 +23,8 @@ export class LibPixiSlider extends LibPixiContainer {
|
|
|
22
23
|
this._slideWidth = 0;
|
|
23
24
|
/** 滑动区域高度 */
|
|
24
25
|
this._slideHeight = 0;
|
|
26
|
+
/** 是否启用循环 */
|
|
27
|
+
this._loop = false;
|
|
25
28
|
/** 记录拖动开始时的X坐标 */
|
|
26
29
|
this._startX = 0;
|
|
27
30
|
/** 偏移量 */
|
|
@@ -36,6 +39,7 @@ export class LibPixiSlider extends LibPixiContainer {
|
|
|
36
39
|
this._slideArea = new Container();
|
|
37
40
|
this._slideWidth = width;
|
|
38
41
|
this._slideHeight = height;
|
|
42
|
+
this._loop = loop;
|
|
39
43
|
this._slideList = slideList;
|
|
40
44
|
this._enableDepth = enableDepth;
|
|
41
45
|
this._depthAlpha = depthAlpha;
|
|
@@ -49,10 +53,7 @@ export class LibPixiSlider extends LibPixiContainer {
|
|
|
49
53
|
item.pivot.set(this._slideWidth / 2, this._slideHeight / 2);
|
|
50
54
|
});
|
|
51
55
|
this.addChild(this._slideArea);
|
|
52
|
-
|
|
53
|
-
this.eventMode = "static";
|
|
54
|
-
this.cursor = "pointer";
|
|
55
|
-
this.on("pointerdown", this._onDragStart);
|
|
56
|
+
libPixiEvent(this, "pointerdown", this._onDragStart.bind(this));
|
|
56
57
|
window.addEventListener("pointermove", this._onDragMove.bind(this));
|
|
57
58
|
window.addEventListener("pointerup", this._onDragEnd.bind(this));
|
|
58
59
|
}
|
|
@@ -68,39 +69,36 @@ export class LibPixiSlider extends LibPixiContainer {
|
|
|
68
69
|
* @param index 索引
|
|
69
70
|
*/
|
|
70
71
|
_slideTo(index) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
onUpdate: () => {
|
|
77
|
-
this._setDepth();
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
this._currentIndex = 0;
|
|
81
|
-
}
|
|
82
|
-
else if (index > this._pageNum) {
|
|
83
|
-
// 回弹到最后一张
|
|
84
|
-
gsap.to(this._slideArea, {
|
|
85
|
-
x: -this._pageNum * this._slideWidth,
|
|
86
|
-
duration: 0.5,
|
|
87
|
-
onUpdate: () => {
|
|
88
|
-
this._setDepth();
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
this._currentIndex = this._pageNum;
|
|
72
|
+
let x = 0;
|
|
73
|
+
if (this._loop) {
|
|
74
|
+
this._currentIndex =
|
|
75
|
+
(index + this._slideList.length) % this._slideList.length;
|
|
76
|
+
x = -this._currentIndex * this._slideWidth;
|
|
92
77
|
}
|
|
93
78
|
else {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
79
|
+
if (index < 0) {
|
|
80
|
+
// 回弹到第一张
|
|
81
|
+
x = 0;
|
|
82
|
+
this._currentIndex = 0;
|
|
83
|
+
}
|
|
84
|
+
else if (index > this._pageNum) {
|
|
85
|
+
// 回弹到最后一张
|
|
86
|
+
x = -this._pageNum * this._slideWidth;
|
|
87
|
+
this._currentIndex = this._pageNum;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
// 正常滑动
|
|
91
|
+
x = -index * this._slideWidth;
|
|
92
|
+
this._currentIndex = index;
|
|
93
|
+
}
|
|
103
94
|
}
|
|
95
|
+
gsap.to(this._slideArea, {
|
|
96
|
+
x,
|
|
97
|
+
duration: 0.25,
|
|
98
|
+
onUpdate: () => {
|
|
99
|
+
this._setDepth();
|
|
100
|
+
},
|
|
101
|
+
});
|
|
104
102
|
this.slideCallback(this._currentIndex, this._pageNum);
|
|
105
103
|
}
|
|
106
104
|
/** @description 开始拖动 */
|
package/README.md
CHANGED
|
@@ -114,6 +114,8 @@ app.stage.addChild(box);
|
|
|
114
114
|
|
|
115
115
|
\- [LibPixiTable-数字表格](#LibPixiTable-数字表格)
|
|
116
116
|
|
|
117
|
+
\- [LibPixiParticleMove-粒子移动特效](#LibPixiParticleMove-粒子移动特效)
|
|
118
|
+
|
|
117
119
|
### 方法
|
|
118
120
|
|
|
119
121
|
\- [LibPixiAudio-音频播放器](#LibPixiAudio-音频播放器)
|
|
@@ -153,12 +155,39 @@ app.stage.addChild(box);
|
|
|
153
155
|
> 自定义文本类
|
|
154
156
|
|
|
155
157
|
```ts
|
|
156
|
-
const text = new LibPixiJs.Base.LibPixiText(
|
|
157
|
-
text: "Hello World!",
|
|
158
|
-
fontSize: 50,
|
|
159
|
-
fontColor: "red",
|
|
160
|
-
});
|
|
158
|
+
const text = new LibPixiJs.Base.LibPixiText(LibPixiTextParams);
|
|
161
159
|
this.addChild(text);
|
|
160
|
+
|
|
161
|
+
interface LibPixiTextParams {
|
|
162
|
+
/** 文本内容 */
|
|
163
|
+
text: string | number;
|
|
164
|
+
/** 字体大小 */
|
|
165
|
+
fontSize?: number;
|
|
166
|
+
/** 字体颜色 */
|
|
167
|
+
fontColor?: any;
|
|
168
|
+
/** 是否描边 */
|
|
169
|
+
stroke?: boolean;
|
|
170
|
+
/** 描边颜色 */
|
|
171
|
+
strokeColor?: string | number;
|
|
172
|
+
/** 描边宽度 */
|
|
173
|
+
strokeThickness?: number;
|
|
174
|
+
/** 字体样式 */
|
|
175
|
+
fontFamily?: string;
|
|
176
|
+
/** 字体粗细 */
|
|
177
|
+
fontWeight?: TextStyleFontWeight;
|
|
178
|
+
/** 是否换行 */
|
|
179
|
+
wordWrap?: boolean;
|
|
180
|
+
/** 换行宽度 */
|
|
181
|
+
wordWrapWidth?: number;
|
|
182
|
+
/** 行高 */
|
|
183
|
+
lineHeight?: number;
|
|
184
|
+
/** 对齐方式 */
|
|
185
|
+
align?: TextStyleAlign;
|
|
186
|
+
/** 缩进,单位为字数 */
|
|
187
|
+
indent?: number;
|
|
188
|
+
/** 阴影-颜色 角度 模糊度 阴影距离 */
|
|
189
|
+
shadow?: [string, number, number, number];
|
|
190
|
+
}
|
|
162
191
|
```
|
|
163
192
|
|
|
164
193
|
### LibPixiBitText-位图
|
|
@@ -166,6 +195,11 @@ this.addChild(text);
|
|
|
166
195
|
> 自定义位图文本
|
|
167
196
|
|
|
168
197
|
```ts
|
|
198
|
+
/**
|
|
199
|
+
* @param fontName 字体名称
|
|
200
|
+
* @param defaultFontSize 默认字体大小
|
|
201
|
+
*/
|
|
202
|
+
|
|
169
203
|
//所有文字使用同一个字体大小
|
|
170
204
|
const font = new LibPixiBitText("FontName", 16);
|
|
171
205
|
const fontText = font.createText("10");
|
|
@@ -184,6 +218,12 @@ this.addChild(fontText2);
|
|
|
184
218
|
> 自定义容器大小及背景色
|
|
185
219
|
|
|
186
220
|
```ts
|
|
221
|
+
/**
|
|
222
|
+
* @param width 容器宽度
|
|
223
|
+
* @param height 容器高度
|
|
224
|
+
* @param bgColor 背景色
|
|
225
|
+
* @param overHidden 是否溢出裁剪
|
|
226
|
+
*/
|
|
187
227
|
const box = new LibPixiJs.Base.LibPixiContainer(100, 100, "#fff", true);
|
|
188
228
|
this.addChild(box);
|
|
189
229
|
```
|
|
@@ -193,12 +233,27 @@ this.addChild(box);
|
|
|
193
233
|
> 自定义矩形背景色
|
|
194
234
|
|
|
195
235
|
```ts
|
|
196
|
-
const rect = new LibPixiRectBgColor(
|
|
197
|
-
width: 100,
|
|
198
|
-
height: 100,
|
|
199
|
-
bgColor: "red",
|
|
200
|
-
});
|
|
236
|
+
const rect = new LibPixiRectBgColor(LibPixiRectBgColorParams);
|
|
201
237
|
this.addChild(rect);
|
|
238
|
+
|
|
239
|
+
interface LibPixiRectBgColorParams {
|
|
240
|
+
/** 宽度 */
|
|
241
|
+
width: number;
|
|
242
|
+
/** 高度 */
|
|
243
|
+
height: number;
|
|
244
|
+
/** 背景颜色 */
|
|
245
|
+
bgColor?: string | number;
|
|
246
|
+
/** 透明度 */
|
|
247
|
+
alpha?: number;
|
|
248
|
+
/** 圆角半径 */
|
|
249
|
+
radius?: number | number[];
|
|
250
|
+
/** 边框宽度 */
|
|
251
|
+
borderWidth?: number;
|
|
252
|
+
/** 边框颜色 */
|
|
253
|
+
borderColor?: string;
|
|
254
|
+
/** 是否启用变色功能 */
|
|
255
|
+
enableTint?: boolean;
|
|
256
|
+
}
|
|
202
257
|
```
|
|
203
258
|
|
|
204
259
|
### LibPixiSpine-动画
|
|
@@ -233,6 +288,31 @@ this.bgSpine = new LibPixiSpine("spine_buyfree", {
|
|
|
233
288
|
},
|
|
234
289
|
],
|
|
235
290
|
});
|
|
291
|
+
|
|
292
|
+
interface OnUpdateParams {
|
|
293
|
+
x: number;
|
|
294
|
+
y: number;
|
|
295
|
+
rotate: number;
|
|
296
|
+
scaleX: number;
|
|
297
|
+
scaleY: number;
|
|
298
|
+
}
|
|
299
|
+
interface LibPixiSpineParams {
|
|
300
|
+
/** 默认是否可见 */
|
|
301
|
+
visible?: boolean;
|
|
302
|
+
/** 挂点列表 */
|
|
303
|
+
followPointList?: {
|
|
304
|
+
/** 挂点名称 */
|
|
305
|
+
boneName: string;
|
|
306
|
+
/** 跟随的精灵或容器 */
|
|
307
|
+
follow: Container;
|
|
308
|
+
/** 是否启用角度 */
|
|
309
|
+
angleFollow?: boolean;
|
|
310
|
+
/** 是否启用缩放 */
|
|
311
|
+
scaleFollow?: boolean;
|
|
312
|
+
/** 更新回调,不传则接受内置挂点更新 */
|
|
313
|
+
onUpdate?: (config: OnUpdateParams) => void;
|
|
314
|
+
}[];
|
|
315
|
+
}
|
|
236
316
|
```
|
|
237
317
|
|
|
238
318
|
### LibPixiParticleMove-粒子容器
|
|
@@ -240,19 +320,139 @@ this.bgSpine = new LibPixiSpine("spine_buyfree", {
|
|
|
240
320
|
> 利用贝塞尔曲线实现粒子移动
|
|
241
321
|
|
|
242
322
|
```ts
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
323
|
+
const libParticleMove = new LibPixiJs.Components.Base.LibPixiParticleMove({
|
|
324
|
+
start: { x: 0, y: window.innerHeight },
|
|
325
|
+
control: [
|
|
326
|
+
{ x: 1000, y: 750 },
|
|
327
|
+
{ x: 500, y: 250 },
|
|
328
|
+
],
|
|
329
|
+
end: { x: 0, y: 0 },
|
|
330
|
+
container: PIXI.Assets.get("fly.png"),
|
|
331
|
+
duration: 1,
|
|
332
|
+
showControl: true,
|
|
333
|
+
ease: "power1.in",
|
|
334
|
+
particleConfig: {
|
|
335
|
+
frequency: 0.001,
|
|
336
|
+
blendMode: "add",
|
|
337
|
+
lifetime: {
|
|
338
|
+
min: 0.01,
|
|
339
|
+
max: 1,
|
|
340
|
+
},
|
|
341
|
+
alpha: {
|
|
342
|
+
start: 1,
|
|
343
|
+
end: 0,
|
|
344
|
+
},
|
|
345
|
+
color: {
|
|
346
|
+
start: "#fff96c",
|
|
347
|
+
end: "#ff837f",
|
|
348
|
+
},
|
|
349
|
+
scale: {
|
|
350
|
+
start: 2,
|
|
351
|
+
end: 3,
|
|
352
|
+
},
|
|
353
|
+
rotation: {
|
|
354
|
+
min: 0,
|
|
355
|
+
max: 360,
|
|
356
|
+
},
|
|
357
|
+
rotate: {
|
|
358
|
+
min: 0,
|
|
359
|
+
max: 360,
|
|
360
|
+
},
|
|
361
|
+
speed: {
|
|
362
|
+
start: 0,
|
|
363
|
+
end: 0,
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
|
|
367
|
+
onDestroy: (destroy) => {
|
|
368
|
+
gsap.to(libParticleMove, {
|
|
369
|
+
alpha: 0,
|
|
370
|
+
onComplete: () => {
|
|
371
|
+
destroy()
|
|
372
|
+
}
|
|
373
|
+
})
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
app.stage.addChild(libParticleMove);
|
|
377
|
+
|
|
378
|
+
export interface LibPixiParticleMoveParams {
|
|
379
|
+
/** 粒子JSON资源 */
|
|
380
|
+
container: Container;
|
|
381
|
+
/** 运动时长 */
|
|
382
|
+
duration: number;
|
|
383
|
+
/** 粒子开始位置 */
|
|
384
|
+
start: { x: number; y: number };
|
|
385
|
+
/** 粒子控制点 */
|
|
386
|
+
control: { x: number; y: number }[];
|
|
387
|
+
/** 粒子结束点 */
|
|
388
|
+
end: { x: number; y: number };
|
|
389
|
+
/** 运动曲线 */
|
|
390
|
+
ease?: gsap.EaseString;
|
|
391
|
+
/** 是否显示控制点,调试使用 */
|
|
392
|
+
showControl?: boolean;
|
|
393
|
+
/** 是否循环,调试使用 */
|
|
394
|
+
loop?: boolean;
|
|
395
|
+
/** 是否启用粒子容器 */
|
|
396
|
+
enableParticleContainer?: boolean;
|
|
397
|
+
/** 粒子配置 */
|
|
398
|
+
particleConfig: {
|
|
399
|
+
/** 随机时长 */
|
|
400
|
+
lifetime: {
|
|
401
|
+
/** 最小时长 */
|
|
402
|
+
min: number;
|
|
403
|
+
/** 最大时长 */
|
|
404
|
+
max: number;
|
|
405
|
+
};
|
|
406
|
+
/** 混合模式 */
|
|
407
|
+
blendMode?: string;
|
|
408
|
+
/** 频率,秒/个 */
|
|
409
|
+
frequency?: number;
|
|
410
|
+
/** 透明度变化 */
|
|
411
|
+
alpha?: {
|
|
412
|
+
/** 开始透明度 */
|
|
413
|
+
start: number;
|
|
414
|
+
/** 结束透明度 */
|
|
415
|
+
end: number;
|
|
416
|
+
};
|
|
417
|
+
/** 颜色变化 */
|
|
418
|
+
color?: {
|
|
419
|
+
/** 开始颜色 */
|
|
420
|
+
start: string;
|
|
421
|
+
/** 结束颜色 */
|
|
422
|
+
end: string;
|
|
423
|
+
};
|
|
424
|
+
/** 随机缩放变化 */
|
|
425
|
+
scale?: {
|
|
426
|
+
/** 最小 */
|
|
427
|
+
start: number;
|
|
428
|
+
/** 最大 */
|
|
429
|
+
end: number;
|
|
430
|
+
};
|
|
431
|
+
/** 随机偏移角度变化 */
|
|
432
|
+
rotation?: {
|
|
433
|
+
/** 最小角度 */
|
|
434
|
+
min: number;
|
|
435
|
+
/** 最大角度 */
|
|
436
|
+
max: number;
|
|
437
|
+
};
|
|
438
|
+
/** 随机自身旋转角度变化 */
|
|
439
|
+
rotate?: {
|
|
440
|
+
/** 最小角度 */
|
|
441
|
+
min: number;
|
|
442
|
+
/** 最大角度 */
|
|
443
|
+
max: number;
|
|
444
|
+
};
|
|
445
|
+
/** 移动速度,像素 */
|
|
446
|
+
speed?: {
|
|
447
|
+
/** 开始速度,不能为0,可无限接近0 */
|
|
448
|
+
start: number;
|
|
449
|
+
/** 结束速度,开始速度会衰减到结束速度 */
|
|
450
|
+
end: number;
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
/** 头部粒子到达终点后触发,可在此设置隐藏动画,隐藏动画结束后调用 destroy 参数进行销毁 */
|
|
454
|
+
onDestroy?: (destroy: () => void) => void;
|
|
455
|
+
}
|
|
256
456
|
```
|
|
257
457
|
|
|
258
458
|
## Custom-定制
|
package/Utils/LibPixiEvent.d.ts
CHANGED
|
@@ -12,5 +12,6 @@ export interface LibPixiEventParams {
|
|
|
12
12
|
* @param eventName 事件名称
|
|
13
13
|
* @param callback 回调函数
|
|
14
14
|
* @returns 停止监听
|
|
15
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
|
|
15
16
|
*/
|
|
16
17
|
export declare const libPixiEvent: (v: Container, eventName: keyof DisplayObjectEvents, callback: (event: FederatedPointerEvent) => void, params?: LibPixiEventParams) => () => void;
|
package/Utils/LibPixiEvent.js
CHANGED
|
@@ -18,6 +18,7 @@ const debounceImmediate = (func, wait) => {
|
|
|
18
18
|
* @param eventName 事件名称
|
|
19
19
|
* @param callback 回调函数
|
|
20
20
|
* @returns 停止监听
|
|
21
|
+
* @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiEvent-事件注册
|
|
21
22
|
*/
|
|
22
23
|
export const libPixiEvent = (v, eventName, callback, params = {}) => {
|
|
23
24
|
const { once = false, debounce = false, debounceTime = 1000 } = params;
|