melonJS
    Preparing search index...

    Function tone

    • Fire a single-shot envelope-shaped oscillator on the shared getAudioContext context. Designed for the "just play a beep" niche where loading an audio file is overkill — UI clicks, hit confirms, retro arcade-style cues, placeholder feedback during prototyping.

      Multi-partial freq makes chimes, bells, and simple chords a single call; pitchSlide covers percussive pitch-drops and rising stings. The context is shared with file-based playback, so the usual browser autoplay gating applies: the first call after a user gesture lets every subsequent call play.

      Requires WebAudio. When WebAudio is not supported (or audio is explicitly disabled) this is a silent no-op: getAudioContext returns null and nothing is scheduled. Use the return value of getAudioContext to detect that case up front if your game wants to show a "no audio" badge or fall back to a different feedback channel.

      Parameters

      • opts: ToneOptions

        the ToneOptions (frequency, duration, envelope, pan, slide). See the interface for per-field defaults.

      Returns void

      // simple UI click
      me.audio.tone({ freq: 1200, duration: 0.08, pitchSlide: 0.5 });
      // chime, panned right, two partials a fifth apart
      me.audio.tone({ freq: [880, 1320], duration: 0.4, gain: 0.18, pan: 0.5 });
      // descending "thud" — square wave with a wide pitch drop
      me.audio.tone({ freq: 200, duration: 0.15, wave: "square", pitchSlide: 0.25 });