Skip to content

Commit

Permalink
Fix orderedArt handling, add example for it.
Browse files Browse the repository at this point in the history
Also, lock down ecstatic so that http-server works on Windows.
  • Loading branch information
andrewstart committed Oct 26, 2019
1 parent 1ba4336 commit 5752e31
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 56 deletions.
1 change: 1 addition & 0 deletions docs/examples/images/spaceship.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"frames":{"hullFront":{"frame":{"x":0,"y":69,"w":44,"h":88},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":44,"h":88},"sourceSize":{"w":44,"h":88}},"hullRear":{"frame":{"x":24,"y":0,"w":48,"h":58},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":48,"h":58},"sourceSize":{"w":48,"h":58}},"leftEngine":{"frame":{"x":45,"y":69,"w":23,"h":68},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":23,"h":68},"sourceSize":{"w":23,"h":68}},"leftWing":{"frame":{"x":73,"y":0,"w":44,"h":52},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":44,"h":52},"sourceSize":{"w":44,"h":52}},"rightEngine":{"frame":{"x":0,"y":0,"w":23,"h":68},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":23,"h":68},"sourceSize":{"w":23,"h":68}},"rightWing":{"frame":{"x":73,"y":101,"w":44,"h":52},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":44,"h":52},"sourceSize":{"w":44,"h":52}},"weaponPod":{"frame":{"x":73,"y":53,"w":30,"h":47},"rotated":false,"trimmed":false,"spriteSourceSize":{"x":0,"y":0,"w":30,"h":47},"sourceSize":{"w":30,"h":47}}},"meta":{"app":"https://www.leshylabs.com/apps/sstool/","version":"Leshy SpriteSheet Tool v0.8.4","image":"spaceship.png","size":{"w":117,"h":157},"scale":1}}
Binary file added docs/examples/images/spaceship.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h1>Emitter Examples</h1>
<li><a href="fountain.html">Fountain</a></li>
<li><a href="coins.html">Animated Coins</a></li>
<li><a href="animatedBubbles.html">Animated Bubbles</a></li>
<li><a href="spaceshipDestruction.html">Spaceship Destruction</a></li>
<li><a href="particleContainerPerformance.html">Particle Container Performance</a></li>
</ul>
</div>
Expand Down
93 changes: 93 additions & 0 deletions docs/examples/spaceshipDestruction.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!DOCTYPE html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Spaceship Destruction</title>
<meta name="description" content="Spaceship Destruction">
<link rel="stylesheet" href="css/main.css">

<!-- Required dependencies -->
<script src="libs/pixi.js/dist/pixi.js"></script>
<script src="../dist/pixi-particles.js"></script>

<!-- Example scaffolding -->
<script src="js/ParticleExample.js"></script>

</head>
<body>
<div id="framerate"></div>
<div id="instructions">Click Anywhere</div>
<canvas id="stage" width="400" height="400"></canvas>
<script>

// See js/ParticleExample.js for actual setup
new ParticleExample(
// The image to use
{
spritesheet: "images/spaceship.json",
art: [
"weaponPod",
"leftWing",
"rightEngine",
"hullFront",
"weaponPod",
"rightWing",
"hullRear",
"leftEngine"
]
},

// Emitter configuration, edit this to change the look
// of the emitter
{
"alpha": {
"start": 1,
"end": 1
},
"scale": {
"start": 1,
"end": 1
},
"color": {
"start": "ffffff",
"end": "666666"
},
"speed": {
"start": 100,
"end": 50
},
"startRotation": {
"min": 0,
"max": 360
},
"rotationSpeed": {
"min": 30,
"max": 360
},
"lifetime": {
"min": 2,
"max": 2
},
// long enough for one burst
"frequency": 0.05,
"emitterLifetime": 0.06,
"maxParticles": 1000,
"pos": {
"x": 0,
"y": 0
},
"addAtBack": false,
// bursts happen in waves
"spawnType": "burst",
// enough particles per wave to handle all ship parts
"particlesPerWave": 8,
"particleSpacing": 0,
"angleStart": 0,
// The important part here - use each image/art object once instead of random selections
"orderedArt": true
}
);
</script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"electron": "^4.0.6",
"eslint": "^4.18.2",
"gh-pages": "^2.0.0",
"http-server": "*",
"http-server": "^0.11.1",
"ncp": "^2.0.0",
"pixi.js": "^4.2.2",
"rimraf": "^2.5.4",
Expand Down
33 changes: 20 additions & 13 deletions src/Emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,6 @@ export class Emitter
* Setting this to false requires calling the update function manually.
*/
protected _autoUpdate: boolean;
/**
* If the emmitter is emitting arts in order as provided in `particleImages`.
* Effective only when `particleImages` has multiple arts.
* This is particularly useful for PathParticles, in case you need to emit a body in an order.
* For example: dragon - [Head, body1, body2, ..., tail]
*/
public orderedArt: boolean;
/**
* A number keeping index of currently applied image. Used to emit arts in order.
*/
Expand Down Expand Up @@ -368,7 +361,6 @@ export class Emitter
this._origConfig = null;
this._origArt = null;
this._autoUpdate = false;
this.orderedArt = false;
this._currentImageIndex = -1;
this._destroyWhenComplete = false;
this._completeCallback = null;
Expand All @@ -387,6 +379,17 @@ export class Emitter
this.updateOwnerPos = this.updateOwnerPos;
}

/**
* If the emitter is using particle art in order as provided in `particleImages`.
* Effective only when `particleImages` has multiple art options.
* This is particularly useful ensuring that each art shows up once, in case you need to emit a body in an order.
* For example: dragon - [Head, body1, body2, ..., tail]
*/
public get orderedArt() { return this._currentImageIndex !== -1; }
public set orderedArt(value) {
this._currentImageIndex = value ? 0 : -1;
}

/**
* Time between particle spawns in seconds. If this value is not a number greater than 0,
* it will be set to 1 (particle per second) to prevent infinite loops.
Expand Down Expand Up @@ -884,19 +887,23 @@ export class Emitter
//set a random texture if we have more than one
if(this.particleImages.length > 1)
{
if(this.orderedArt)
// if using ordered art
if(this._currentImageIndex !== -1)
{
this._currentImageIndex++;
// get current art index, then increment for the next particle
p.applyArt(this.particleImages[this._currentImageIndex++]);
// loop around if needed
if(this._currentImageIndex < 0 || this._currentImageIndex >= this.particleImages.length)
{
this._currentImageIndex = 0;
this._currentImageIndex = 0;
}
}
// otherwise grab a random one
else
{
this._currentImageIndex = Math.floor(Math.random() * this.particleImages.length);
p.applyArt(this.particleImages[Math.floor(Math.random() * this.particleImages.length)]);
}
p.applyArt(this.particleImages[this._currentImageIndex]);

}
else
{
Expand Down
79 changes: 37 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -525,12 +525,7 @@ [email protected], assert-plus@^1.0.0:
resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525"
integrity sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=

async@^1.5.2:
version "1.5.2"
resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a"
integrity sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=

async@^2.6.1:
async@^2.6.1, async@^2.6.2:
version "2.6.3"
resolved "https://registry.npmjs.org/async/-/async-2.6.3.tgz#d72625e2344a3656e3a3ad4fa749fa83299d82ff"
integrity sha512-zflvls11DCy+dQWzTW2dzuilv8Z5X/pjfmZOWba6TNIVDm+2UDaJmXSOXlasHKfNBs8oo3M0aT50fDEWfKZjXg==
Expand Down Expand Up @@ -733,7 +728,7 @@ [email protected]:

[email protected]:
version "1.0.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
resolved "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=

combined-stream@^1.0.6, combined-stream@~1.0.6:
Expand Down Expand Up @@ -780,7 +775,7 @@ [email protected], core-util-is@~1.0.0:

corser@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/corser/-/corser-2.0.1.tgz#8eda252ecaab5840dcd975ceb90d9370c819ff87"
resolved "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz#8eda252ecaab5840dcd975ceb90d9370c819ff87"
integrity sha1-jtolLsqrWEDc2XXOuQ2TcMgZ/4c=

cross-spawn@^5.0.1, cross-spawn@^5.1.0:
Expand Down Expand Up @@ -820,7 +815,7 @@ [email protected], debug@^2.1.3, debug@^2.2.0:
dependencies:
ms "2.0.0"

debug@^3.0.0, debug@^3.1.0, debug@^3.2.6:
debug@^3.0.0, debug@^3.1.0, debug@^3.1.1:
version "3.2.6"
resolved "https://registry.yarnpkg.com/debug/-/debug-3.2.6.tgz#e83d17de16d8a7efb7717edbe5fb10135eee629b"
integrity sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==
Expand Down Expand Up @@ -897,9 +892,9 @@ ecc-jsbn@~0.1.1:
safer-buffer "^2.1.0"

ecstatic@^3.0.0:
version "3.3.2"
resolved "https://registry.yarnpkg.com/ecstatic/-/ecstatic-3.3.2.tgz#6d1dd49814d00594682c652adb66076a69d46c48"
integrity sha512-fLf9l1hnwrHI2xn9mEDT7KIi22UDqA2jaCwyCbSUJh9a1V+LEUSL/JO/6TIz/QyuBURWUHrFL5Kg2TtO1bkkog==
version "3.2.1"
resolved "https://registry.npmjs.org/ecstatic/-/ecstatic-3.2.1.tgz#1196a74d63d71d28dea807ed2b6183062671a206"
integrity sha512-BAdHx9LOCG1fwxY8MIydUBskl8UUQrYeC3WE14FA1DPlBzqoG1aOgEkypcSpmiiel8RAj8gW1s40RrclfrpGUg==
dependencies:
he "^1.1.1"
mime "^1.6.0"
Expand Down Expand Up @@ -1143,16 +1138,16 @@ eventemitter3@^2.0.0:
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-2.0.3.tgz#b5e1079b59fb5e1ba2771c0a993be060a58c99ba"
integrity sha1-teEHm1n7XhuidxwKmTvgYKWMmbo=

eventemitter3@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7"
integrity sha512-tvtQIeLVHjDkJYnzf2dgVMxfuSGJeM/7UCG17TT4EumTfNtF+0nebF/4zWOIkCreAbtNqhGEboB6BWrwqNaw4Q==

eventemitter3@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163"
integrity sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA==

eventemitter3@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.0.tgz#d65176163887ee59f386d64c82610b696a4a74eb"
integrity sha512-qerSRB0p+UDEssxTtm6EDKcE7W4OaoisfIMl4CngyEhjpYglocpNg6UEqCvemdGhosAsg4sO2dXJOdyBifPGCg==

execa@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777"
Expand Down Expand Up @@ -1290,11 +1285,11 @@ flat-cache@^1.2.1:
write "^0.2.1"

follow-redirects@^1.0.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.7.0.tgz#489ebc198dc0e7f64167bd23b03c4c19b5784c76"
integrity sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==
version "1.9.0"
resolved "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.9.0.tgz#8d5bcdc65b7108fe1508649c79c12d732dcedb4f"
integrity sha512-CRcPzsSIbXyVDl0QI01muNDu69S8trU4jArW9LpOt2WtC6LyUJetcIrmfHsRBx7/Jb6GHJUiuqyYxPooFfNt6A==
dependencies:
debug "^3.2.6"
debug "^3.0.0"

forever-agent@~0.6.1:
version "0.6.1"
Expand Down Expand Up @@ -1445,7 +1440,7 @@ has-flag@^3.0.0:

he@^1.1.1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
resolved "https://registry.npmjs.org/he/-/he-1.2.0.tgz#84ae65fa7eafb165fddb61566ae14baf05664f0f"
integrity sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==

highlight.js@^9.13.1:
Expand All @@ -1459,17 +1454,17 @@ hosted-git-info@^2.1.4:
integrity sha512-7T/BxH19zbcCTa8XkMlbK5lTo1WtgkFi3GvdWEyNuc4Vex7/9Dqbnpsf4JMydcfj9HCg4zUWFTL3Za6lapg5/w==

http-proxy@^1.8.1:
version "1.17.0"
resolved "https://registry.yarnpkg.com/http-proxy/-/http-proxy-1.17.0.tgz#7ad38494658f84605e2f6db4436df410f4e5be9a"
integrity sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g==
version "1.18.0"
resolved "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.0.tgz#dbe55f63e75a347db7f3d99974f2692a314a6a3a"
integrity sha512-84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPpQ==
dependencies:
eventemitter3 "^3.0.0"
eventemitter3 "^4.0.0"
follow-redirects "^1.0.0"
requires-port "^1.0.0"

http-server@*:
http-server@^0.11.1:
version "0.11.1"
resolved "https://registry.yarnpkg.com/http-server/-/http-server-0.11.1.tgz#2302a56a6ffef7f9abea0147d838a5e9b6b6a79b"
resolved "https://registry.npmjs.org/http-server/-/http-server-0.11.1.tgz#2302a56a6ffef7f9abea0147d838a5e9b6b6a79b"
integrity sha512-6JeGDGoujJLmhjiRGlt8yK8Z9Kl0vnl/dQoQZlc4oeqaUoAKQg94NILLfrY3oWzSyFaQCVNTcKE5PZ3cH8VP9w==
dependencies:
colors "1.0.3"
Expand Down Expand Up @@ -1839,7 +1834,7 @@ mime-types@^2.1.12, mime-types@~2.1.19:

mime@^1.6.0:
version "1.6.0"
resolved "https://registry.yarnpkg.com/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
resolved "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz#32cd9e5c64553bd58d19a568af452acff04981b1"
integrity sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==

mimic-fn@^1.0.0:
Expand Down Expand Up @@ -1874,7 +1869,7 @@ minimist@~0.0.1:
resolved "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf"
integrity sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=

[email protected], mkdirp@0.5.x, mkdirp@^0.5.1:
[email protected], mkdirp@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903"
integrity sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=
Expand Down Expand Up @@ -1992,12 +1987,12 @@ onetime@^2.0.0:

opener@~1.4.0:
version "1.4.3"
resolved "https://registry.yarnpkg.com/opener/-/opener-1.4.3.tgz#5c6da2c5d7e5831e8ffa3964950f8d6674ac90b8"
resolved "https://registry.npmjs.org/opener/-/opener-1.4.3.tgz#5c6da2c5d7e5831e8ffa3964950f8d6674ac90b8"
integrity sha1-XG2ixdflgx6P+jlklQ+NZnSskLg=

[email protected], optimist@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
resolved "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686"
integrity sha1-2j6nRob6IaGaERwybpDrFaAZZoY=
dependencies:
minimist "~0.0.1"
Expand Down Expand Up @@ -2215,13 +2210,13 @@ pluralize@^7.0.0:
integrity sha512-ARhBOdzS3e41FbkW/XWrTEtukqqLoK5+Z/4UeDaLuSW+39JPeFgs4gCGqsrJHVZX0fUrx//4OF0K1CUGwlIFow==

portfinder@^1.0.13:
version "1.0.20"
resolved "https://registry.yarnpkg.com/portfinder/-/portfinder-1.0.20.tgz#bea68632e54b2e13ab7b0c4775e9b41bf270e44a"
integrity sha512-Yxe4mTyDzTd59PZJY4ojZR8F+E5e97iq2ZOHPz3HDgSvYC5siNad2tLooQ5y5QHyQhc3xVqvyk/eNA3wuoa7Sw==
version "1.0.25"
resolved "https://registry.npmjs.org/portfinder/-/portfinder-1.0.25.tgz#254fd337ffba869f4b9d37edc298059cb4d35eca"
integrity sha512-6ElJnHBbxVA1XSLgBp7G1FiCkQdlqGzuF7DswL5tcea+E8UpuvPU7beVAjjRwCioTS9ZluNbu+ZyRvgTsmqEBg==
dependencies:
async "^1.5.2"
debug "^2.2.0"
mkdirp "0.5.x"
async "^2.6.2"
debug "^3.1.1"
mkdirp "^0.5.1"

prelude-ls@~1.1.2:
version "1.1.2"
Expand Down Expand Up @@ -2286,7 +2281,7 @@ punycode@^2.1.0:

qs@~2.3.3:
version "2.3.3"
resolved "https://registry.yarnpkg.com/qs/-/qs-2.3.3.tgz#e9e85adbe75da0bbe4c8e0476a086290f863b404"
resolved "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz#e9e85adbe75da0bbe4c8e0476a086290f863b404"
integrity sha1-6eha2+ddoLvkyOBHaghikPhjtAQ=

qs@~6.5.2:
Expand Down Expand Up @@ -2435,7 +2430,7 @@ require-uncached@^1.0.3:

requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
resolved "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
integrity sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=

resolve-from@^1.0.0:
Expand Down Expand Up @@ -3004,7 +2999,7 @@ uglify-js@^3.1.4:

union@~0.4.3:
version "0.4.6"
resolved "https://registry.yarnpkg.com/union/-/union-0.4.6.tgz#198fbdaeba254e788b0efcb630bc11f24a2959e0"
resolved "https://registry.npmjs.org/union/-/union-0.4.6.tgz#198fbdaeba254e788b0efcb630bc11f24a2959e0"
integrity sha1-GY+9rrolTniLDvy2MLwR8kopWeA=
dependencies:
qs "~2.3.3"
Expand All @@ -3028,7 +3023,7 @@ urix@^0.1.0:

url-join@^2.0.5:
version "2.0.5"
resolved "https://registry.yarnpkg.com/url-join/-/url-join-2.0.5.tgz#5af22f18c052a000a48d7b82c5e9c2e2feeda728"
resolved "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz#5af22f18c052a000a48d7b82c5e9c2e2feeda728"
integrity sha1-WvIvGMBSoACkjXuCxenC4v7tpyg=

url@^0.11.0:
Expand Down

0 comments on commit 5752e31

Please sign in to comment.