Created
February 11, 2017 15:13
-
-
Save bartread/964c015009b2ec46b6254e55f0d90840 to your computer and use it in GitHub Desktop.
Playing a sound effect in arcade.ly games
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function _play(effect) { | |
if (!areSfxEnabledFlag || !effect) { | |
return; | |
} | |
var buffer = effect.buffer; | |
if (!buffer) { | |
return; | |
} | |
var source = context.createBufferSource(); | |
source.buffer = buffer; | |
effect.mediaSource = source; | |
source.connect(effect.gain); | |
if (!source.start) { | |
source.start = source.noteOn; | |
} | |
source.start(0); | |
} | |
/* | |
This code is licensed under the terms of the MIT License as described | |
in LICENSE.txt. | |
Copyright (c) 2015 - 2017 Bart Read, arcade.ly (https://arcade.ly), | |
and bartread.com Ltd (http://www.bartread.com/) | |
The soundConfiguration service is a per-game service, implemented by | |
games at https://arcade.ly, that provides configuration for sound | |
effects and music to the sfx service, thus allowing them to be played. | |
*/ | |
function _playByName(name) { | |
_play(service[name]); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment