音频


GameMaker Studio 2 has a complete audio engine that is based on the *.ogg, *.mp3 and *.wav sound formats. 添加到IDE的这些类别的声音可以通过下面的函数使用。对于比基本的音效更复杂的事物或者播放单个音乐片段,你可以参考高级的音频函数,你可以用它们修改声音的播放方式。此外,还有一系列专用函数,专门用于流式传输的音频和定位音频( 3D声音效果以及分组音频)。

IMPORTANT! When using audio on the HTML5 target, you should be aware that not all browsers support Web Audio and so may not play any sound for your project when run. You can get a general idea of Web Audio support from the following link: Can I Use Web Audio?.


The following functions are for dealing with audio in the most straightforward and simple way possible, avoiding the use of emitters and permitting the user to generate sounds and play music easily as these sounds are always generated at the listener position (see below for more details on the listener) and so are generally not affected by any changes to the listener:


The following functions are designed to give more control over how the audio engine works, and how the sounds played through it will be "heard" by the listener. As such it is recommended that you have a good working knowledge of how the rest of the GameMaker Studio 2 audio engine works before using any of the following functions:


Further advanced functionality, like setting listeners, recording audio, or synchronising multiple audio tracks over time can all be found from the sub-sections listed below:

  1. 音频发射器
  2. 音频侦听器
  3. 音频组
  4. 音频缓冲区
  5. 音频同步


Web Audio


When creating games for the HTML5 target platform, the audio engine requires Web Audio support, and this in turn mans that sometimes your audio won't play when or how you expect it. This is because the Web Audio context may not be running or may stop running when your game is being played. What causes this varies greatly between browsers, and even between different versions of the same browser, and so detecting when the web audio context status changes is very important, eg: to detect when the context changes and pause/start looping audio like background music.

To help with this issue, GameMaker Studio 2 has two separate ways to detect the change in Web Audio context status, either using the following function:

Or using the Asynchronous System Event, which will be triggered whenever the Web Audio status changes. In this event you will get the built in async_load DS map populated with the key "event_type" which in turn will hold the string "audio_system_status" if it is an audio event. When this key exists, there will also be a further "status" key which will be either "available" or "unavailable". Note that this event will be triggered on all platforms, but on everything except HTML5 it will only be triggered once on Game Start when the audio engine is first initialised. For more information please see the section:

  1. 异步事件