custom-pixi-particles 4.20.0 → 4.21.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.
|
@@ -20,6 +20,16 @@ export default class MoveToPointBehaviour extends Behaviour {
|
|
|
20
20
|
* The speed at which particles move towards the target point (units per second).
|
|
21
21
|
*/
|
|
22
22
|
speed: number;
|
|
23
|
+
/**
|
|
24
|
+
* If true, particles will be marked as "dead" (lifeTime >= maxLifeTime)
|
|
25
|
+
* once they reach the targetPoint while this behaviour is active.
|
|
26
|
+
*/
|
|
27
|
+
killOnArrival: boolean;
|
|
28
|
+
resetMaxLifeTime: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The distance threshold to consider a particle "at" the target point.
|
|
31
|
+
*/
|
|
32
|
+
arrivalThreshold: number;
|
|
23
33
|
/**
|
|
24
34
|
* Priority determines execution order. A lower number means it runs later.
|
|
25
35
|
* This should run after default position behaviours to override the particle's position.
|
|
@@ -58,6 +68,9 @@ export default class MoveToPointBehaviour extends Behaviour {
|
|
|
58
68
|
y: number;
|
|
59
69
|
};
|
|
60
70
|
speed: number;
|
|
71
|
+
killOnArrival: boolean;
|
|
72
|
+
resetMaxLifeTime: boolean;
|
|
73
|
+
arrivalThreshold: number;
|
|
61
74
|
priority: number;
|
|
62
75
|
name: string;
|
|
63
76
|
};
|
|
@@ -21,6 +21,16 @@ export default class MoveToPointBehaviour extends Behaviour {
|
|
|
21
21
|
* The speed at which particles move towards the target point (units per second).
|
|
22
22
|
*/
|
|
23
23
|
this.speed = 100;
|
|
24
|
+
/**
|
|
25
|
+
* If true, particles will be marked as "dead" (lifeTime >= maxLifeTime)
|
|
26
|
+
* once they reach the targetPoint while this behaviour is active.
|
|
27
|
+
*/
|
|
28
|
+
this.killOnArrival = false;
|
|
29
|
+
this.resetMaxLifeTime = false;
|
|
30
|
+
/**
|
|
31
|
+
* The distance threshold to consider a particle "at" the target point.
|
|
32
|
+
*/
|
|
33
|
+
this.arrivalThreshold = 1.0;
|
|
24
34
|
/**
|
|
25
35
|
* Priority determines execution order. A lower number means it runs later.
|
|
26
36
|
* This should run after default position behaviours to override the particle's position.
|
|
@@ -49,6 +59,10 @@ export default class MoveToPointBehaviour extends Behaviour {
|
|
|
49
59
|
// The particle will continue its movement based on other behaviours.
|
|
50
60
|
return;
|
|
51
61
|
}
|
|
62
|
+
// If the particle is already considered dead by other means, don't process further.
|
|
63
|
+
if (particle.isDead()) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
52
66
|
const dx = this.targetPoint.x - particle.x;
|
|
53
67
|
const dy = this.targetPoint.y - particle.y;
|
|
54
68
|
const distance = Math.sqrt(dx * dx + dy * dy);
|
|
@@ -58,10 +72,30 @@ export default class MoveToPointBehaviour extends Behaviour {
|
|
|
58
72
|
particle.velocity.set(0, 0);
|
|
59
73
|
particle.acceleration.set(0, 0);
|
|
60
74
|
// If particle is already at or very close to the target
|
|
61
|
-
if (distance <
|
|
62
|
-
// Using a small threshold to prevent jittering
|
|
75
|
+
if (distance < this.arrivalThreshold) {
|
|
63
76
|
particle.x = this.targetPoint.x;
|
|
64
77
|
particle.y = this.targetPoint.y;
|
|
78
|
+
if (this.killOnArrival) {
|
|
79
|
+
// Mark the particle as dead. The Emitter will pick this up and remove it.
|
|
80
|
+
// Ensure maxLifeTime is positive; otherwise, this won't "kill" it effectively.
|
|
81
|
+
if (particle.maxLifeTime > 0) {
|
|
82
|
+
particle.lifeTime = particle.maxLifeTime;
|
|
83
|
+
if (this.resetMaxLifeTime) {
|
|
84
|
+
particle.maxLifeTime = 0;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// If maxLifeTime is 0 or negative (infinite),
|
|
89
|
+
// we can't use it to kill. Consider an alternative
|
|
90
|
+
// or ensure particles using this feature have a finite life.
|
|
91
|
+
// For now, we'll just set it to a high value, but ideally,
|
|
92
|
+
// this feature is for particles with defined lifespans.
|
|
93
|
+
// Or, one could introduce a specific "killNow" flag on the particle
|
|
94
|
+
// if the Emitter was modified to check for it.
|
|
95
|
+
// Simplest for now is to rely on a positive maxLifeTime.
|
|
96
|
+
// If maxLifeTime is not > 0, the particle won't be "killed" by this mechanism.
|
|
97
|
+
}
|
|
98
|
+
}
|
|
65
99
|
}
|
|
66
100
|
else {
|
|
67
101
|
const moveAmount = this.speed * deltaTime;
|
|
@@ -69,6 +103,14 @@ export default class MoveToPointBehaviour extends Behaviour {
|
|
|
69
103
|
// If the movement step is enough to reach the target, snap to target
|
|
70
104
|
particle.x = this.targetPoint.x;
|
|
71
105
|
particle.y = this.targetPoint.y;
|
|
106
|
+
if (this.killOnArrival) {
|
|
107
|
+
if (particle.maxLifeTime > 0) {
|
|
108
|
+
particle.lifeTime = particle.maxLifeTime;
|
|
109
|
+
if (this.resetMaxLifeTime) {
|
|
110
|
+
particle.maxLifeTime = 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
72
114
|
}
|
|
73
115
|
else {
|
|
74
116
|
// Move towards the target
|
|
@@ -102,6 +144,9 @@ export default class MoveToPointBehaviour extends Behaviour {
|
|
|
102
144
|
active: this.active,
|
|
103
145
|
targetPoint: { x: this.targetPoint.x, y: this.targetPoint.y },
|
|
104
146
|
speed: this.speed,
|
|
147
|
+
killOnArrival: this.killOnArrival,
|
|
148
|
+
resetMaxLifeTime: this.resetMaxLifeTime,
|
|
149
|
+
arrivalThreshold: this.arrivalThreshold,
|
|
105
150
|
priority: this.priority,
|
|
106
151
|
name: this.getName(),
|
|
107
152
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoveToPointBehaviour.js","sourceRoot":"","sources":["../../../src/lib/behaviour/MoveToPointBehaviour.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B;;;;GAIG;AACH,MAAM,CAAC,OAAO,OA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