Timers, sounds, menus and animations as components
Timer, AudioSource, UI nodes and AnimationPlayer: whole jobs from plain data.
Four components do a whole job from plain data, with no system of yours (scene files and the editor's node kinds are made of them).
Each sends an event whose entity is the node it happened to.
Timer(core):Timer({ waitTime: 2, autostart: true })sendsTimerTimeoutevery 2 seconds (once withoneShot). Use it for waves, cooldowns and spawns rather than countingtime.dtyourself.AudioSource(Audio()): a sound that belongs to an entity.AudioSource({ sound: 'assets/fire.ogg', loop: true, autoplay: true, positional: '2d', range: 12 })pans and fades with the camera ('3d': around it).playingis the switch;AudioFinishedwhen a sound that doesn't loop ends. A one-off effect is stillaudio.play(name, { at }).- UI nodes (
UI()): a menu or HUD as entities, aControl(Control.preset('bottom', { w, h, margin })) plusUiPanel,UiLabel,UiButton,UiSlider,UiToggle,UiTextInputandUiBoxrows and columns. They are themed, scaled and kept clear of the platform's corners like views; a click on one never reaches the game; keys and a gamepad move focus;modal: truemakes a menu. ReadUiPressed,UiToggled,UiChanged,UiSubmitted. A view (ui.view) is still the quickest HUD in code. AnimationPlayer(Animation()): keyframes on the nodes around it, fromanims/*.anim.json(parseAnimchecks one): fields eased between keys, call and signal keys, loops and crossfades;AnimationFinishedwhen one ends. Name the nodes it moves (world.spawn(list, { name: 'Door' })): tracks find them by path from the player's parent.- Files a scene uses with no code: a sprite sheet is a
*.sheet.json({ "image": "assets/hero.png", "frameWidth": 32, "frameHeight": 32, "clips": { "run": [2, 3, 4, 5] } }) that aSpritenames as itsimage(aSpriteAnimplays its clips); aTileMappaintstiles(rows of tile numbers,"0 1 . 2", from itsstartcell) from a*.tileset.json({ "image", "tileWidth", "tileHeight" }); project.json'saudio.effectsnames synthesized effects anAudioSourceplays like'coin'. - In a test,
game.run(seconds)plays them all, andui.nodes.press(button),ui.nodes.type(input, text)andui.nodes.setValue(slider, 5)do what a player would, with or without a screen.