Audio
Choosing sounds
Section titled “Choosing sounds”Every sound field in the Inspector (Sound, Jump Sound, Music, a script’s HitSound) has three buttons: Play to hear it, a list of every sound in the project to pick from, and the Sound Maker, which opens on the field’s sound if it was made there (or on a new one) and sets whatever it saves. Dragging a sound from the Assets panel onto a field sets it too. A field naming a file that isn’t there turns red. Griff plays WAV, MP3 and OGG files.
Muting the editor
Section titled “Muting the editor”The speaker button on the toolbar (Game → Mute, Ctrl+Shift+M) silences everything the editor plays: the game in play mode, the windows of Play with Players, the Sound Maker and previews. The sound device is shut while it’s on, and the game plays on just as it would with sound (its music keeps time, and scripts play their sounds as before), so nothing about the game changes: its own Muted and volume settings, and its saves, are left alone. It’s kept between sessions. GRIFF_MUTE=1 makes an editor silent for that session whatever Mute says, without changing the saved choice (Mute switched there isn’t kept), and everything it starts (an exported game run from it) inherits it; exported games take --mute too.
Music and sound players
Section titled “Music and sound players”Add a Background Music to a scene and its Music starts with the scene, crossfading over Fade seconds from whatever was playing (the same music just carries on, so every level can name it). A Sound Player plays its Sound whenever its Message is sent (Score from a pickup, a switch’s On Message, an enemy’s Death Message) and, with On Start, when it appears; Pitch Variation changes its pitch a little at random each time, so a sound heard over and over doesn’t grate, and Positional makes it come from where it is. A Health plays its Hurt Sound when damage lands and its Death Sound when it dies, and a Button plays its Sound when clicked.
Sounds in the level
Section titled “Sounds in the level”Add a Sound Source to a waterfall, a fire or a machine and its Sound plays over and over, loudest near the middle of the screen and fading out by its Range (0 is heard everywhere at full volume: rain, wind), from the left or right speaker as it’s to that side. Untick Playing to start it silent; a switch’s Targets turn it on and off. Its Pitch can change as it plays: an engine that revs. Scripts can play a one-off sound where something is with Game.PlaySoundAt.
Keeping the beat
Section titled “Keeping the beat”Add a Beat Clock (next to the scene’s Background Music is a good place) and it keeps time with whatever music is playing: a scene’s, a room’s or a script’s. It counts what’s been heard, not what’s been sent to the sound card, which holds a few hundredths of a second of sound before it reaches the speakers; so a beat lands with the drum you hear. Speakers with a delay of their own (Bluetooth headphones, a TV) are allowed for too, by each player’s audio offset, which they set by tapping along to the clicks of a Calibration (Entity → Audio → Create Calibration Screen); see Rhythm games. On every beat it sends its Beat Message (Beat, with the beat’s number, 0 for the first) and on the first beat of every bar its Bar Message (Bar, with the bar’s number), so a Sound Player can tick along and a script do anything on the beat with On<int>("Beat", beat => ...). Music made with Audio → New Music says its own tempo, so the clock needs no setting up; for other music set its Tempo (beats a minute), and Offset (seconds into the music of its first beat) for music with a lead-in, or to nudge the beat until it sits right. Beats Per Bar is 4 (3 for a waltz). As the music loops the count carries on (beat 33 after a 32-beat tune, not 0 again), each loop starting on a beat of its own. With no music it waits. While it plays, its Beat, Bar, Beat In Bar (0 is the downbeat), Phase (how far through the beat, 0 to 1), Beats (the count with the fraction), Position (seconds into the music) and Current Tempo say where it is, and scripts can time a press to the music with SecondsFromBeat (negative just before a beat, positive just after) or follow its BeatStarted and BarStarted events. Give anything a Beat Pulse and it bops on the beat: drawn bigger by its Size as each beat lands, shrinking back before the next, Every that many beats (4 for once a bar), with its children; only how it’s drawn changes, not its transform or collider. A pulse follows the scene’s first clock, or the one on the entity its Clock names. Spawners, Shooters, Movers and Switches step to the beat too: set their Beats and they spawn, fire, set off for their next point or flip on or off on every that many beats instead of counting seconds. A spawner or shooter still waits out its Delay first, then goes on the next beat it steps on (a spawner with no room waits for the next one after that; a shooter with an Action fires on the beat while it’s held). A mover sets off on a step, gets to the next point at its Speed (faster if that wouldn’t get it there by the next step), and waits there for the step after rather than for its Wait; it waits at its start for the first. A switch flips whoever has worked it, so with Targets it brings out spikes every other bar, or opens a gate on the beat (a plate goes back to how it’s held). Beat Offset shifts each one later by that many beats, so two turrets on every 2 beats with offsets 0 and 1 take turns, and Clock names the clock to step to (empty is the scene’s first). Scripts can step the same way with clock.OnBeat(every, offset), true in the frame a beat it steps on lands. Scripts can read the music’s time themselves: Audio.MusicTime is the seconds heard (before the player’s audio offset, which a clock takes off), Audio.MusicLength how long it lasts and Audio.MusicTempo the tempo it says; clock.SecondsFrom(beat) times a press against any beat, and Audio.PlayMetronome(tempo) plays a click track as the music. Audio.PlayMusicFrom(music, seconds) starts music part way in (Note Lanes carry their song on that way after a pause or a rewind), and music that doesn’t loop, played to its end, is no longer the music (Audio.Music is empty) so a clock following it stops. Note Lanes play a chart of notes to a clock and judge each press against it: see Rhythm games. In a network game every machine keeps time with its own music, and the host’s clock sends the messages to everyone.