pixi-particle-system 1.0.0 → 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 +190 -0
- package/dist/behavior/built-in/RotationBehavior.d.ts +12 -3
- package/dist/behavior/built-in/RotationBehavior.d.ts.map +1 -1
- package/dist/index.js +199 -171
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# PixiJS Particle System
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<p align="center">
|
|
5
|
+
<img src="https://img.shields.io/badge/typescript-%23007ACC.svg?style=for-the-badge&logo=typescript&logoColor=white" />
|
|
6
|
+
<img src="https://img.shields.io/badge/vite-%23646CFF.svg?style=for-the-badge&logo=vite&logoColor=white" />
|
|
7
|
+
<img src="https://img.shields.io/badge/pnpm-%234a4a4a.svg?style=for-the-badge&logo=pnpm&logoColor=f69220" />
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
<p align="center">
|
|
11
|
+
<a href="https://danielpokladek.github.io/pixi-particle-system/first-steps/what-is-it.html">Documentation</a>
|
|
12
|
+
| <a href="https://danielpokladek.github.io/pixi-particle-system/editor/">Interactive Editor</a>
|
|
13
|
+
| <a href="https://danielpokladek.github.io/pixi-particle-system/api/classes/Emitter.html">API Reference</a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
A modern, flexible particle system for **PixiJS** - inspired by the original [Particle Emitter](https://github.com/pixijs-userland/particle-emitter/tree/master), but rebuilt with a clean TypeScript-first architecture and more expressive API.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
- Built for PixiJS, provides seamless integration with V8's `ParticleContainer` and `Particle` objects.
|
|
20
|
+
- Provides strong typing, great IntelliSense and predictable API.
|
|
21
|
+
- Behavior orientated design allows for pluggable behaviors for custom effects.
|
|
22
|
+
- Flexible yet simple API, start small and scale up to advanced usage.
|
|
23
|
+
- Optimized for real-time effects.
|
|
24
|
+
- Comes with built-in behaviors to get started immediately:
|
|
25
|
+
- `AlphaBehavior`
|
|
26
|
+
- `ColorBehavior`
|
|
27
|
+
- `MovementBehavior`
|
|
28
|
+
- `RotationBehavior`
|
|
29
|
+
- `ScaleBehavior`
|
|
30
|
+
- `SpawnBehavior`
|
|
31
|
+
- `TextureBehavior`
|
|
32
|
+
|
|
33
|
+
### Installation
|
|
34
|
+
|
|
35
|
+
> This library is still under active early development and not yet published to NPM.
|
|
36
|
+
|
|
37
|
+
You can clone the repo and install it locally:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
git clone git@github.com:danielpokladek/pixi-particle-system.git
|
|
41
|
+
cd pixi-particle-system
|
|
42
|
+
pnpm install
|
|
43
|
+
pnpm build
|
|
44
|
+
```
|
|
45
|
+
Or add it directly as a GitHub dependency:
|
|
46
|
+
```bash
|
|
47
|
+
pnpm add github:danielpokladek/pixi-particle-system
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Quick Start
|
|
51
|
+
|
|
52
|
+
Here's the minimum required to get particles on the screen:
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { Emitter } from "pixi-particle-system";
|
|
56
|
+
import { ParticleContainer } from "pixi.js";
|
|
57
|
+
|
|
58
|
+
// Create a particle container and add it to your app/stage
|
|
59
|
+
const container = new ParticleContainer();
|
|
60
|
+
app.stage.addChild(container);
|
|
61
|
+
|
|
62
|
+
// Create an emitter (the "brain" of the particle system)
|
|
63
|
+
const emitter = new Emitter(container);
|
|
64
|
+
|
|
65
|
+
// Start emitting particles
|
|
66
|
+
emitter.play();
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
> Particles default to a 1x1 white texture.
|
|
70
|
+
> If you don't see anything, assign a custom texture using `TextureBehavior` or custom scale using `ScaleBehavior`.
|
|
71
|
+
|
|
72
|
+
### Configuration Example
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const emitter = new Emitter(container, {
|
|
76
|
+
emitterVersion: 0,
|
|
77
|
+
minParticleLifetime: 0.4,
|
|
78
|
+
maxParticleLifetime: 0.4,
|
|
79
|
+
spawnInterval: 0.01,
|
|
80
|
+
spawnChance: 1,
|
|
81
|
+
maxParticles: 50,
|
|
82
|
+
addAtBack: true,
|
|
83
|
+
particlesPerWave: 1,
|
|
84
|
+
|
|
85
|
+
alphaBehavior: {
|
|
86
|
+
listData: {
|
|
87
|
+
list: [
|
|
88
|
+
{ value: 0.0, time: 0.0 },
|
|
89
|
+
{ value: 1.0, time: 0.5 },
|
|
90
|
+
{ value: 0.0, time: 1.0 }
|
|
91
|
+
]
|
|
92
|
+
},
|
|
93
|
+
mode: "list"
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
colorBehavior: {
|
|
97
|
+
listData: {
|
|
98
|
+
list: [
|
|
99
|
+
{ value: "#ff0000", time: 0 },
|
|
100
|
+
{ value: "#00ff00", time: 0.5 },
|
|
101
|
+
{ value: "#0000ff", time: 1 },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
mode: "random",
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
movementBehavior: {
|
|
108
|
+
xListData: {
|
|
109
|
+
list: [
|
|
110
|
+
{ value: 50, time: 0 },
|
|
111
|
+
{ value: 150, time: 1 },
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
yListData: {
|
|
115
|
+
list: [
|
|
116
|
+
{ value: -100, time: 0 },
|
|
117
|
+
{ value: 450, time: 1 },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
space: "local",
|
|
121
|
+
mode: "acceleration",
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
scaleBehavior: {
|
|
125
|
+
mode: "list",
|
|
126
|
+
listData: {
|
|
127
|
+
list: [
|
|
128
|
+
{ value: 0, time: 0 },
|
|
129
|
+
{ value: 100, time: 1 },
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
spawnBehavior: {
|
|
135
|
+
shape: "rectangle",
|
|
136
|
+
width: 400,
|
|
137
|
+
height: 400,
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
emitter.play();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Documentation
|
|
145
|
+
|
|
146
|
+
Full documentation, API reference, and guides: **TBA**
|
|
147
|
+
(Will be linked once GitHub Pages deployment is live.)
|
|
148
|
+
|
|
149
|
+
### Development
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
git clone git@github.com:danielpokladek/pixi-particle-system.git
|
|
153
|
+
git cd pixi-particle-system
|
|
154
|
+
pnpm install
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Build (production)
|
|
158
|
+
```bash
|
|
159
|
+
pnpm build
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Build & Watch (development)
|
|
163
|
+
```bash
|
|
164
|
+
pnpm dev
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Generate Documentation
|
|
168
|
+
```bash
|
|
169
|
+
pnpm docs:build
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Contribute
|
|
173
|
+
|
|
174
|
+
Contributions are welcome!
|
|
175
|
+
|
|
176
|
+
If you'd like to help:
|
|
177
|
+
|
|
178
|
+
1. Fork the repo.
|
|
179
|
+
2. Create a feature/bugfix branch.
|
|
180
|
+
3. Submit a PR with your changes.
|
|
181
|
+
|
|
182
|
+
Contribution guidelines will be added soon.
|
|
183
|
+
|
|
184
|
+
### Change Log
|
|
185
|
+
|
|
186
|
+
[Releases](https://github.com/danielpokladek/pixi-particle-system/releases)
|
|
187
|
+
|
|
188
|
+
### License
|
|
189
|
+
|
|
190
|
+
This content is released under the [MIT License](https://opensource.org/license/MIT).
|
|
@@ -3,6 +3,10 @@ import { Emitter } from '../../Emitter';
|
|
|
3
3
|
import { BaseParticleData, IEmitterParticle } from '../../particle/EmitterParticle';
|
|
4
4
|
import { BehaviorOrder, BehaviorSingleListConfig, BehaviorStaticConfig } from '../../util/Types';
|
|
5
5
|
import { EmitterBehavior, InitBehavior, UpdateBehavior } from '../EmitterBehavior';
|
|
6
|
+
/**
|
|
7
|
+
* Type describing the modes in which RotationBehavior can operate.
|
|
8
|
+
*/
|
|
9
|
+
type RotationBehaviorMode = "static" | "list" | "random" | "random" | "acceleration" | "direction";
|
|
6
10
|
/**
|
|
7
11
|
* Type defining the configuration for direction mode.
|
|
8
12
|
* @group Behavior/RotationBehavior/
|
|
@@ -34,7 +38,9 @@ export type AccelerationConfigType = {
|
|
|
34
38
|
/**
|
|
35
39
|
* Type defining the configuration for RotationBehavior.
|
|
36
40
|
*/
|
|
37
|
-
export type RotationBehaviorConfig =
|
|
41
|
+
export type RotationBehaviorConfig = {
|
|
42
|
+
useDegrees?: boolean;
|
|
43
|
+
} & (DirectionConfigType | BehaviorStaticConfig<number> | BehaviorSingleListConfig<number> | AccelerationConfigType);
|
|
38
44
|
/**
|
|
39
45
|
* Behavior used to control the rotation of particles over their lifetime.
|
|
40
46
|
*
|
|
@@ -53,6 +59,7 @@ export type RotationBehaviorConfig = DirectionConfigType | BehaviorStaticConfig<
|
|
|
53
59
|
* ```ts
|
|
54
60
|
* // Apply a static rotation of 45 degrees to all particles.
|
|
55
61
|
* rotationBehavior.applyConfig({
|
|
62
|
+
* mode: "static",
|
|
56
63
|
* value: Math.PI / 4
|
|
57
64
|
* });
|
|
58
65
|
*
|
|
@@ -69,6 +76,7 @@ export type RotationBehaviorConfig = DirectionConfigType | BehaviorStaticConfig<
|
|
|
69
76
|
export declare class RotationBehavior<DataType extends BaseParticleData, ParticleType extends IEmitterParticle<DataType> = IEmitterParticle<DataType>> extends EmitterBehavior<RotationBehaviorConfig, DataType, ParticleType> implements InitBehavior<DataType, ParticleType>, UpdateBehavior<DataType, ParticleType> {
|
|
70
77
|
private readonly _list;
|
|
71
78
|
private _mode;
|
|
79
|
+
private _useDegrees;
|
|
72
80
|
private _staticValue;
|
|
73
81
|
private _startRotation;
|
|
74
82
|
private _acceleration;
|
|
@@ -91,8 +99,8 @@ export declare class RotationBehavior<DataType extends BaseParticleData, Particl
|
|
|
91
99
|
/**
|
|
92
100
|
* Current mode used by the behavior.
|
|
93
101
|
*/
|
|
94
|
-
get mode():
|
|
95
|
-
set mode(value:
|
|
102
|
+
get mode(): RotationBehaviorMode;
|
|
103
|
+
set mode(value: RotationBehaviorMode);
|
|
96
104
|
/**
|
|
97
105
|
* Static rotation value applied to all particles.
|
|
98
106
|
*/
|
|
@@ -129,4 +137,5 @@ export declare class RotationBehavior<DataType extends BaseParticleData, Particl
|
|
|
129
137
|
*/
|
|
130
138
|
protected reset(): void;
|
|
131
139
|
}
|
|
140
|
+
export {};
|
|
132
141
|
//# sourceMappingURL=RotationBehavior.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RotationBehavior.d.ts","sourceRoot":"","sources":["../../../src/behavior/built-in/RotationBehavior.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RotationBehavior.d.ts","sourceRoot":"","sources":["../../../src/behavior/built-in/RotationBehavior.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACH,gBAAgB,EAChB,gBAAgB,EACnB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACH,aAAa,EACb,wBAAwB,EACxB,oBAAoB,EACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACH,eAAe,EACf,YAAY,EACZ,cAAc,EACjB,MAAM,oBAAoB,CAAC;AAE5B;;GAEG;AACH,KAAK,oBAAoB,GACnB,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,cAAc,GACd,WAAW,CAAC;AAElB;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAC9B;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC;CAC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