Limit sound repetition per process frame.
This commit is contained in:
@@ -453,7 +453,8 @@ CandyFucker.prototype = {
|
||||
[
|
||||
{
|
||||
Name: "Explosion",
|
||||
Url: "sfx/explosion1.wav"
|
||||
Url: "sfx/explosion1.wav",
|
||||
Limit: 1
|
||||
},
|
||||
{
|
||||
Name: "PickCandy",
|
||||
@@ -475,6 +476,7 @@ CandyFucker.prototype = {
|
||||
this.UpdateInfoDisplay();
|
||||
},
|
||||
Proc: function () {
|
||||
window.Sounds.ResetCounters();
|
||||
if (this.Locked) {
|
||||
if (this.Falling) {
|
||||
if (!this.Board.CandyFall()) {
|
||||
|
||||
@@ -442,6 +442,7 @@ ImageLoader.prototype = {
|
||||
//
|
||||
var SoundLoader = function () {
|
||||
this.Sounds = {};
|
||||
this.Limits = {};
|
||||
};
|
||||
SoundLoader.prototype = {
|
||||
LoadSounds: function (soundsList, funcOnLoad) {
|
||||
@@ -450,11 +451,16 @@ SoundLoader.prototype = {
|
||||
|
||||
var soundName;
|
||||
|
||||
var i,
|
||||
n;
|
||||
var i, n;
|
||||
for (i = 0, n = soundsList.length; i < n; i++) {
|
||||
soundName = soundsList[i].Name;
|
||||
this.Sounds[soundName] = new Audio();
|
||||
if (soundsList[i].Limit) {
|
||||
this.Limits[soundName] = {
|
||||
Max: soundsList[i].Limit,
|
||||
Count: 0
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var self = this;
|
||||
@@ -488,10 +494,23 @@ SoundLoader.prototype = {
|
||||
privateOnLoad();
|
||||
},
|
||||
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 sndCopy = sndOrig.cloneNode();
|
||||
sndCopy.play();
|
||||
},
|
||||
ResetCounters: function () {
|
||||
for (var name in this.Limits) {
|
||||
if (this.Limits.hasOwnProperty(name)) {
|
||||
this.Limits[name].Count = 0;
|
||||
}
|
||||
}
|
||||
},
|
||||
Debug: false
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user