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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(examples): the starfield drifts by Velocity
esengine1585c1c607ea
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex f0ff650c4..9650f5553 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -24,6 +24,12 @@ published separately; it ships inside the editor.it runs, so switching a boss back on cannot un-switch a prop that was switchedoff on its own. `set_entity_active` is the same door for automation.+- **The starfield drifts by `Velocity`.** Forty stars each had their `y`+ decremented by a system every frame, which is the one thing the engine's own+ `Velocity` component does — and nothing in the corpus had ever carried it.+ The prefab does now; the scroll system is down to putting a star that has left+ the bottom back at the top, and `Star` is the tag it always was.+- **Six components a shipped scene now authors.** The hull bar's mask inspace-shooter, all three trails in trail-demo, a crosswind through thethird-person demo's ambient motes, a costly patch of mud in the 3D AI example,diff --git a/examples/space-shooter/assets/prefabs/Star.esprefab b/examples/space-shooter/assets/prefabs/Star.esprefabindex 91f705b02..64a108cdf 100644--- a/examples/space-shooter/assets/prefabs/Star.esprefab+++ b/examples/space-shooter/assets/prefabs/Star.esprefab@@ -1,50 +1,62 @@{- "version": "2",- "name": "Star",- "rootEntityId": "0",- "entities": [+ "version": "2",+ "name": "Star",+ "rootEntityId": "0",+ "entities": [+ {+ "prefabEntityId": "0",+ "name": "Star",+ "parent": null,+ "children": [],+ "components": [{- "prefabEntityId": "0",- "name": "Star",- "parent": null,- "children": [],- "components": [- {- "type": "Transform",- "data": {- "position": {- "x": 0,- "y": 0,- "z": -0.5- }- }- },- {- "type": "Sprite",- "data": {- "texture": "@uuid:8f56c884-0439-47f1-86d9-05839abfa6e0",- "size": {- "x": 9,- "y": 9- },- "color": {- "r": 1,- "g": 1,- "b": 1,- "a": 0.7- },- "layer": -1- }- },- {- "type": "Star",- "data": {- "speed": 30,- "layer": 0- }- }- ],- "visible": true+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": -0.5+ }+ }+ },+ {+ "type": "Sprite",+ "data": {+ "texture": "@uuid:8f56c884-0439-47f1-86d9-05839abfa6e0",+ "size": {+ "x": 9,+ "y": 9+ },+ "color": {+ "r": 1,+ "g": 1,+ "b": 1,+ "a": 0.7+ },+ "layer": -1+ }+ },+ {+ "type": "Velocity",+ "data": {+ "linear": {+ "x": 0,+ "y": -30,+ "z": 0+ },+ "angular": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Star",+ "data": {}}- ]-}+ ],+ "visible": true+ }+ ]+}\ No newline at end of filediff --git a/examples/space-shooter/src/components.ts b/examples/space-shooter/src/components.tsindex 69aa6d981..4714799dd 100644--- a/examples/space-shooter/src/components.ts+++ b/examples/space-shooter/src/components.ts@@ -16,10 +16,9 @@ export const Bullet = defineComponent('Bullet', {fromPlayer: true,});-export const Star = defineComponent('Star', {- speed: 30,- layer: 0,-});+// A tag in all but name: what a star DOES is drift, and that is `Velocity` on+// the prefab. This marks the ones the wrap belongs to.+export const Star = defineComponent('Star', {});export const Explosion = defineComponent('Explosion', {timer: 0.3,diff --git a/examples/space-shooter/src/systems/effects.ts b/examples/space-shooter/src/systems/effects.tsindex e1c29ba2b..da8a5f7d8 100644--- a/examples/space-shooter/src/systems/effects.ts+++ b/examples/space-shooter/src/systems/effects.ts@@ -45,14 +45,15 @@ export const explosionSystem = defineSystem({ name: 'ExplosionSystem' });+/**+ * Wrap the starfield. The DRIFT is `Velocity` on each star, integrated by the+ * engine — no physics body, no per-frame arithmetic here; all this does is put a+ * star that has left the bottom back at the top.+ */export const starScrollSystem = defineSystem(- [Res(Time), Query(Mut(Transform), Star)],- (time, query) => {- const dt = time.delta;-- for (const [_entity, transform, star] of query) {- transform.position.y -= star.speed * dt;-+ [Query(Mut(Transform), Star)],+ (query) => {+ for (const [_entity, transform] of query) {if (transform.position.y < -HALF_HEIGHT - 10) {transform.position.y = HALF_HEIGHT + 10;transform.position.x = (Math.random() - 0.5) * HALF_WIDTH * 2;diff --git a/examples/space-shooter/src/systems/setup.ts b/examples/space-shooter/src/systems/setup.tsindex e0a758018..2a559ff31 100644--- a/examples/space-shooter/src/systems/setup.ts+++ b/examples/space-shooter/src/systems/setup.ts@@ -26,7 +26,9 @@ export const setupSystem = defineSystem((Math.random() - 0.5) * HALF_WIDTH * 2,(Math.random() - 0.5) * HALF_HEIGHT * 2,),- propOverride('Star', 'speed', speed),+ // The drift itself is Velocity's, integrated by the engine;+ // this only says how fast this layer of the field moves.+ propOverride('Velocity', 'linear', { x: 0, y: -speed, z: 0 }),propOverride('Sprite', 'color', { r: 1, g: 1, b: 1, a: 0.3 + layer * 0.3 }),],});diff --git a/tools/check-corpus-authoring.mjs b/tools/check-corpus-authoring.mjsindex b095fdc18..0b5c20005 100644--- a/tools/check-corpus-authoring.mjs+++ b/tools/check-corpus-authoring.mjs@@ -120,7 +120,6 @@ const DISPOSITION = {BitmapText: ['owed', 'Create > Bitmap Text exists; every corpus scene uses Text instead, so the pixel-font path ships unwitnessed'],- Velocity: ['owed', 'motion without a physics body — the cheapest thing in the engine, authored nowhere'],};const snapshot = JSON.parse(readFileSync(SNAPSHOT, 'utf8'));