Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

feat(game): hit sparks, and a third entry in the ledger

esengine74fc81beb649
diff --git a/examples/celestial-heights/assets/scenes/main.esscene b/examples/celestial-heights/assets/scenes/main.esscene
index 4d02caeaa..b69748dfe 100644
--- a/examples/celestial-heights/assets/scenes/main.esscene
+++ b/examples/celestial-heights/assets/scenes/main.esscene
@@ -294,6 +294,69 @@
}
]
},
+ {
+ "id": 45,
+ "name": "SparkEmitter",
+ "parent": null,
+ "children": [],
+ "folder": "Environment",
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "ParticleEmitter",
+ "data": {
+ "texture": "@uuid:a036a9cb-e792-40bf-8f6f-9a31b65889a7",
+ "shape": 1,
+ "shapeRadius": 10,
+ "rate": 0,
+ "burstCount": 20,
+ "burstInterval": 0,
+ "duration": 0.06,
+ "looping": false,
+ "playOnStart": false,
+ "maxParticles": 64,
+ "lifetimeMin": 0.25,
+ "lifetimeMax": 0.5,
+ "speedMin": 190,
+ "speedMax": 380,
+ "startSizeMin": 12,
+ "startSizeMax": 20,
+ "endSizeMin": 0,
+ "endSizeMax": 3,
+ "startColor": {
+ "r": 1,
+ "g": 0.86,
+ "b": 0.62,
+ "a": 1
+ },
+ "endColor": {
+ "r": 0.98,
+ "g": 0.35,
+ "b": 0.42,
+ "a": 0
+ },
+ "gravity": {
+ "x": 0,
+ "y": -260
+ },
+ "damping": 1.6,
+ "layer": 4,
+ "blendMode": 1,
+ "enabled": true
+ }
+ }
+ ]
+ },
{
"id": 20,
"name": "Lyra_Player",
diff --git a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
index 9cef1ef39..1e329817b 100644
--- a/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
+++ b/examples/celestial-heights/assets/scenes/moonlit-gallery.esscene
@@ -210,6 +210,69 @@
}
]
},
+ {
+ "id": 45,
+ "name": "SparkEmitter",
+ "parent": null,
+ "children": [],
+ "folder": "Environment",
+ "visible": true,
+ "components": [
+ {
+ "type": "Transform",
+ "data": {
+ "position": {
+ "x": 0,
+ "y": 0,
+ "z": 0
+ }
+ }
+ },
+ {
+ "type": "ParticleEmitter",
+ "data": {
+ "texture": "@uuid:a036a9cb-e792-40bf-8f6f-9a31b65889a7",
+ "shape": 1,
+ "shapeRadius": 10,
+ "rate": 0,
+ "burstCount": 20,
+ "burstInterval": 0,
+ "duration": 0.06,
+ "looping": false,
+ "playOnStart": false,
+ "maxParticles": 64,
+ "lifetimeMin": 0.25,
+ "lifetimeMax": 0.5,
+ "speedMin": 190,
+ "speedMax": 380,
+ "startSizeMin": 12,
+ "startSizeMax": 20,
+ "endSizeMin": 0,
+ "endSizeMax": 3,
+ "startColor": {
+ "r": 1,
+ "g": 0.86,
+ "b": 0.62,
+ "a": 1
+ },
+ "endColor": {
+ "r": 0.98,
+ "g": 0.35,
+ "b": 0.42,
+ "a": 0
+ },
+ "gravity": {
+ "x": 0,
+ "y": -260
+ },
+ "damping": 1.6,
+ "layer": 4,
+ "blendMode": 1,
+ "enabled": true
+ }
+ }
+ ]
+ },
{
"id": 20,
"name": "Lyra_Player",
diff --git a/examples/celestial-heights/assets/textures/spark.png b/examples/celestial-heights/assets/textures/spark.png
new file mode 100644
index 000000000..5d149343b
Binary files /dev/null and b/examples/celestial-heights/assets/textures/spark.png differ
diff --git a/examples/celestial-heights/assets/textures/spark.png.meta b/examples/celestial-heights/assets/textures/spark.png.meta
new file mode 100644
index 000000000..fdce7485f
--- /dev/null
+++ b/examples/celestial-heights/assets/textures/spark.png.meta
@@ -0,0 +1,12 @@
+{
+ "uuid": "a036a9cb-e792-40bf-8f6f-9a31b65889a7",
+ "version": "2.0",
+ "type": "texture",
+ "importer": {
+ "maxSize": 512,
+ "filterMode": "linear",
+ "wrapMode": "clamp",
+ "premultiplyAlpha": false,
+ "sliceBorder": { "left": 0, "right": 0, "top": 0, "bottom": 0 }
+ }
+}
diff --git a/examples/celestial-heights/engine-gaps.mjs b/examples/celestial-heights/engine-gaps.mjs
index 2afd07e36..018566a38 100644
--- a/examples/celestial-heights/engine-gaps.mjs
+++ b/examples/celestial-heights/engine-gaps.mjs
@@ -31,4 +31,24 @@
*/
/** @type {Array<{id: string, hurts: string, workaround: string, fix: string, issue?: string, allows?: string[]}>} */
-export const GAPS = [];
+export const GAPS = [
+ {
+ id: 'particles-simulate-but-do-not-draw',
+ hurts:
+ 'Hits throw no sparks. The emitter is played, the particles exist and they age '
+ + 'out on schedule — read back from the running package, getAliveCount goes 64, 60, '
+ + '33, 9, 0 over about thirty frames — and not one pixel changes. Three captures '
+ + 'taken while they were alive differ by 0 in the box around the player.',
+ workaround:
+ 'None available: the game does the correct thing and the frame does not show it, '
+ + 'so the slice currently ships without hit feedback.',
+ fix:
+ 'Root-cause the draw. Already excluded by measurement: the burst config (a '
+ + 'continuous emitter placed on screen is equally invisible), the emitter position, '
+ + 'the sorting layer (particle-demo keeps drawing after the same sortingLayers and '
+ + 'ySortLayers are added to it), the blend mode, the layer index, and asset '
+ + 'packaging — the texture ships and the emitter reads back texture=1, enabled=true, '
+ + 'layer=2. What is left is what this project has and particle-demo does not: a '
+ + 'tilemap and physics. Bisect from particle-demo\'s scene, adding one at a time.',
+ },
+];
diff --git a/examples/celestial-heights/src/main.ts b/examples/celestial-heights/src/main.ts
index df28e9564..252b09e61 100644
--- a/examples/celestial-heights/src/main.ts
+++ b/examples/celestial-heights/src/main.ts
@@ -19,6 +19,7 @@ import {
pickupSystem, inventoryInputSystem, inventoryBuildSystem, inventorySyncSystem,
} from './systems/inventory';
import { achievementSystem, achievementToastSystem } from './systems/achievements';
+import { hitSparkSystem } from './systems/spark';
import { perceiverFacingSystem } from './ai/wisp';
// Perception, nav following, the behaviour-tree tick and scene switching are
@@ -43,7 +44,7 @@ addSystemSetToSchedule(Schedule.Update, defineSystemSet('gameplay', {
// Damage resolves after everyone has decided to swing, and death after damage,
// so a hit lands in the frame it was thrown rather than the next one.
addSystemSetToSchedule(Schedule.PostUpdate, defineSystemSet('combat', {
- systems: [meleeResolveSystem, damageSystem, deathSystem, invulnerabilitySystem],
+ systems: [meleeResolveSystem, damageSystem, deathSystem, invulnerabilitySystem, hitSparkSystem],
runIf: () => !session.paused,
}));
diff --git a/examples/celestial-heights/src/state.ts b/examples/celestial-heights/src/state.ts
index e1c620d57..761b95d66 100644
--- a/examples/celestial-heights/src/state.ts
+++ b/examples/celestial-heights/src/state.ts
@@ -15,4 +15,6 @@ export const session = {
/** Item kind → how many Lyra is carrying. */
inventory: {} as Record<string, number>,
inventoryOpen: false,
+ /** Settings: whether hit sparks and other flourishes are drawn. */
+ effects: true,
};
diff --git a/examples/celestial-heights/src/systems/spark.ts b/examples/celestial-heights/src/systems/spark.ts
new file mode 100644
index 000000000..615137816
--- /dev/null
+++ b/examples/celestial-heights/src/systems/spark.ts
@@ -0,0 +1,31 @@
+import {
+ defineSystem, Query, Mut, Res, EventReader, GetWorld,
+ Transform, ParticleEmitter, Particle,
+} from 'esengine';
+import { DamageDealt } from '../events';
+import { session } from '../state';
+
+/**
+ * A hit throws sparks. One authored emitter is moved and replayed rather than a
+ * new one spawned per blow: a burst is over in a quarter of a second, and the
+ * texture reference stays in the scene where whoever draws it can find it.
+ */
+export const hitSparkSystem = defineSystem(
+ [EventReader(DamageDealt), Query(Mut(Transform), ParticleEmitter), Res(Particle), GetWorld()],
+ (blows, emitters, particles, world) => {
+ if (!session.effects) return;
+ for (const blow of blows) {
+ if (!world.has(blow.target, Transform)) continue;
+ const at = world.get(blow.target, Transform).position;
+ for (const [entity, transform] of emitters) {
+ transform.position.x = at.x;
+ transform.position.y = at.y;
+ // ENGINE-GAP(particles-simulate-but-do-not-draw): this burst runs
+ // and ages out on schedule; nothing of it appears on screen.
+ particles.play(entity);
+ break;
+ }
+ }
+ },
+ { name: 'HitSparkSystem' },
+);