lyb-pixi-js 1.3.6 → 1.3.8

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.
@@ -1,6 +1,5 @@
1
1
  import { type Container } from "pixi.js";
2
2
  import { Spine } from "@pixi-spine/runtime-3.8";
3
- import "pixi-spine";
4
3
  export interface OnUpdateParams {
5
4
  x: number;
6
5
  y: number;
@@ -1,7 +1,6 @@
1
1
  import { Assets, Ticker } from "pixi.js";
2
2
  import { Spine } from "@pixi-spine/runtime-3.8";
3
3
  import gsap from "gsap";
4
- import "pixi-spine";
5
4
  /** @description 自定义 Spine 动画
6
5
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiSpine-动画
7
6
  */
@@ -74,10 +73,14 @@ export class LibPixiSpine extends Spine {
74
73
  /** @description 销毁动画及挂点 */
75
74
  destroyAll() {
76
75
  Ticker.system.remove(this._loopFn);
77
- this.destroy();
76
+ this.destroy({ children: true });
78
77
  }
79
78
  /** @description 更新渲染 */
80
79
  _loop() {
80
+ if (this.destroyed) {
81
+ Ticker.system.remove(this._loopFn);
82
+ return;
83
+ }
81
84
  this.update(Ticker.system.deltaMS / 1000);
82
85
  this._updateFollowPoint();
83
86
  }
@@ -1,5 +1,5 @@
1
1
  import { Container } from "pixi.js";
2
- import { LibPixiContainer } from '../Base/LibPixiContainer';
2
+ import { LibPixiContainer } from "../Base/LibPixiContainer";
3
3
  export interface LibPixiScrollNumParams {
4
4
  /** 滚动区域宽度 */
5
5
  width: number;
@@ -53,10 +53,22 @@ export declare class LibPixiScrollNum extends LibPixiContainer {
53
53
  * @param animate 是否需要过渡动画
54
54
  */
55
55
  slideTo(index: number, animate?: boolean): void;
56
+ /** @description 设置滚动景深
57
+ * @param containerList 元素列表
58
+ * @param y 拖动Y坐标
59
+ * @param startY 内部将y - startY进行计算
60
+ */
61
+ setDepth(containerList: Container[], y: number, startY?: number): void;
56
62
  /** @description 开始拖动 */
57
63
  private _onDragStart;
58
64
  /** @description 拖动中 */
59
65
  private _onDragMove;
60
66
  /** @description 结束拖动 */
61
67
  private _onDragEnd;
68
+ /** @description 线性插值
69
+ * @param a1 当 t = 0 时,返回 a1
70
+ * @param a2 当 t = 1 时,返回 a2
71
+ * @param t 插值比例,取值范围 0~1
72
+ */
73
+ private lerp;
62
74
  }
@@ -1,6 +1,6 @@
1
1
  import { Graphics } from "pixi.js";
2
2
  import gsap from "gsap";
3
- import { LibPixiContainer } from '../Base/LibPixiContainer';
3
+ import { LibPixiContainer } from "../Base/LibPixiContainer";
4
4
  /** @description 通过鼠标或手指拖动数字列选择数字
5
5
  * @link 使用方法:https://www.npmjs.com/package/lyb-pixi-js#LibPixiScrollNum-数字滑动
6
6
  */
@@ -99,6 +99,35 @@ export class LibPixiScrollNum extends LibPixiContainer {
99
99
  }
100
100
  (_a = this._slideCallback) === null || _a === void 0 ? void 0 : _a.call(this, this._currentIndex);
101
101
  }
102
+ /** @description 设置滚动景深
103
+ * @param containerList 元素列表
104
+ * @param y 拖动Y坐标
105
+ * @param startY 内部将y - startY进行计算
106
+ */
107
+ setDepth(containerList, y, startY = 0) {
108
+ const Y = y - startY;
109
+ const idx = Math.floor(Math.abs(Y) / 70);
110
+ const t = (Math.abs(Y) % 70) / 70;
111
+ const prevIdx = idx - 1;
112
+ const nextIdx = idx + 1;
113
+ const nextIdx2 = idx + 2;
114
+ const curItem = containerList[idx];
115
+ curItem.alpha = this.lerp(0.5, 1, 1 - t);
116
+ curItem.scale.y = this.lerp(0.85, 1, 1 - t);
117
+ if (nextIdx < containerList.length) {
118
+ const nextItem = containerList[nextIdx];
119
+ nextItem.alpha = this.lerp(0.5, 1, t);
120
+ nextItem.scale.y = this.lerp(0.85, 1, t);
121
+ }
122
+ if (nextIdx2 < containerList.length) {
123
+ const nextItem = containerList[nextIdx2];
124
+ nextItem.alpha = this.lerp(0.1, 0.5, t);
125
+ }
126
+ if (prevIdx >= 0) {
127
+ const prevItem = containerList[prevIdx];
128
+ prevItem.alpha = this.lerp(0.1, 0.5, 1 - t);
129
+ }
130
+ }
102
131
  /** @description 开始拖动 */
103
132
  _onDragStart(event) {
104
133
  this._isDragging = true;
@@ -152,4 +181,12 @@ export class LibPixiScrollNum extends LibPixiContainer {
152
181
  // 执行滑动到目标页码
153
182
  this.slideTo(this._currentIndex);
154
183
  }
184
+ /** @description 线性插值
185
+ * @param a1 当 t = 0 时,返回 a1
186
+ * @param a2 当 t = 1 时,返回 a2
187
+ * @param t 插值比例,取值范围 0~1
188
+ */
189
+ lerp(a1, a2, t) {
190
+ return a1 * (1 - t) + a2 * t;
191
+ }
155
192
  }