Limit sound repetition per process frame.

This commit is contained in:
2015-12-08 21:07:50 +01:00
parent 9202e1d51a
commit bdf1e844e3
2 changed files with 24 additions and 3 deletions

View File

@@ -453,7 +453,8 @@ CandyFucker.prototype = {
[ [
{ {
Name: "Explosion", Name: "Explosion",
Url: "sfx/explosion1.wav" Url: "sfx/explosion1.wav",
Limit: 1
}, },
{ {
Name: "PickCandy", Name: "PickCandy",
@@ -475,6 +476,7 @@ CandyFucker.prototype = {
this.UpdateInfoDisplay(); this.UpdateInfoDisplay();
}, },
Proc: function () { Proc: function () {
window.Sounds.ResetCounters();
if (this.Locked) { if (this.Locked) {
if (this.Falling) { if (this.Falling) {
if (!this.Board.CandyFall()) { if (!this.Board.CandyFall()) {

View File

@@ -442,6 +442,7 @@ ImageLoader.prototype = {
// //
var SoundLoader = function () { var SoundLoader = function () {
this.Sounds = {}; this.Sounds = {};
this.Limits = {};
}; };
SoundLoader.prototype = { SoundLoader.prototype = {
LoadSounds: function (soundsList, funcOnLoad) { LoadSounds: function (soundsList, funcOnLoad) {
@@ -450,11 +451,16 @@ SoundLoader.prototype = {
var soundName; var soundName;
var i, var i, n;
n;
for (i = 0, n = soundsList.length; i < n; i++) { for (i = 0, n = soundsList.length; i < n; i++) {
soundName = soundsList[i].Name; soundName = soundsList[i].Name;
this.Sounds[soundName] = new Audio(); this.Sounds[soundName] = new Audio();
if (soundsList[i].Limit) {
this.Limits[soundName] = {
Max: soundsList[i].Limit,
Count: 0
};
}
} }
var self = this; var self = this;
@@ -488,10 +494,23 @@ SoundLoader.prototype = {
privateOnLoad(); privateOnLoad();
}, },
PlaySound: function (name) { PlaySound: function (name) {
if (this.Limits[name]) {
if (this.Limits[name].Max <= this.Limits[name].Count){
return;
}
this.Limits[name].Count++;
}
var sndOrig = this.Sounds[name]; var sndOrig = this.Sounds[name];
var sndCopy = sndOrig.cloneNode(); var sndCopy = sndOrig.cloneNode();
sndCopy.play(); sndCopy.play();
}, },
ResetCounters: function () {
for (var name in this.Limits) {
if (this.Limits.hasOwnProperty(name)) {
this.Limits[name].Count = 0;
}
}
},
Debug: false Debug: false
}; };