mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-26 07:52:50 -05:00
comments on getSoundIndex
This commit is contained in:
parent
9d8819ddc7
commit
dd30e07052
1 changed files with 5 additions and 0 deletions
|
@ -48,17 +48,22 @@ Scratch3SoundBlocks.prototype.playSoundAndWait = function (args, util) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Scratch3SoundBlocks.prototype._getSoundIndex = function (soundName, util) {
|
Scratch3SoundBlocks.prototype._getSoundIndex = function (soundName, util) {
|
||||||
|
// if the sprite has no sounds, return 0
|
||||||
if (util.target.sprite.sounds.length === 0) {
|
if (util.target.sprite.sounds.length === 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
var index;
|
var index;
|
||||||
|
|
||||||
|
// if the sound name is a number, wrapclamp it to a sound index
|
||||||
if (Number(soundName)) {
|
if (Number(soundName)) {
|
||||||
soundName = Number(soundName);
|
soundName = Number(soundName);
|
||||||
var len = util.target.sprite.sounds.length;
|
var len = util.target.sprite.sounds.length;
|
||||||
index = MathUtil.wrapClamp(soundName, 1, len) - 1;
|
index = MathUtil.wrapClamp(soundName, 1, len) - 1;
|
||||||
} else {
|
} else {
|
||||||
|
// else get the index for that sound of that name
|
||||||
index = util.target.getSoundIndexByName(soundName);
|
index = util.target.getSoundIndexByName(soundName);
|
||||||
|
// use zero if there is no sound by that name
|
||||||
|
// to match scratch 2.0 behavior, we should instead play no sound in this case
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue