mirror of
https://github.com/overte-org/overte.git
synced 2025-04-26 19:16:21 +02:00
interval is working
This commit is contained in:
parent
1bfe14c70e
commit
c26d7e61b5
2 changed files with 25 additions and 11 deletions
|
@ -33,7 +33,8 @@ Entities.setPacketsPerSecond(6000);
|
||||||
|
|
||||||
var DEFAULT_SOUND_DATA = {
|
var DEFAULT_SOUND_DATA = {
|
||||||
volume: 0.5,
|
volume: 0.5,
|
||||||
loop: false
|
loop: false,
|
||||||
|
interval: -1 // An interval of -1 means this sound only plays once (if it's non-looping)
|
||||||
};
|
};
|
||||||
|
|
||||||
print("EBL STARTING AC SCRIPT");
|
print("EBL STARTING AC SCRIPT");
|
||||||
|
@ -55,8 +56,10 @@ function messageReceived(channel, message, sender) {
|
||||||
url: soundData.url,
|
url: soundData.url,
|
||||||
volume: soundData.volume || DEFAULT_SOUND_DATA.volume,
|
volume: soundData.volume || DEFAULT_SOUND_DATA.volume,
|
||||||
loop: soundData.loop || DEFAULT_SOUND_DATA.loop,
|
loop: soundData.loop || DEFAULT_SOUND_DATA.loop,
|
||||||
needsPlay: true,
|
interval: soundData.interval || DEFAULT_SOUND_DATA.interval,
|
||||||
position: Entities.getEntityProperties(entityID, "position").position
|
readyToPlay: true,
|
||||||
|
position: Entities.getEntityProperties(entityID, "position").position,
|
||||||
|
timeSinceLastPlay: 0
|
||||||
};
|
};
|
||||||
if (!soundUrls[soundData.url]) {
|
if (!soundUrls[soundData.url]) {
|
||||||
// We need to download sound before we add it to our map
|
// We need to download sound before we add it to our map
|
||||||
|
@ -75,23 +78,33 @@ function messageReceived(channel, message, sender) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function update(deltaTime) {
|
||||||
// Go through each sound and play it if it needs to be played
|
// Go through each sound and play it if it needs to be played
|
||||||
for (var property in soundEntityMap) {
|
for (var potentialEntity in soundEntityMap) {
|
||||||
if(!soundEntityMap.hasOwnProperty(property)) {
|
if(!soundEntityMap.hasOwnProperty(potentialEntity)) {
|
||||||
// The current property is not a direct propert of soundEntityMap
|
// The current property is not a direct propert of soundEntityMap
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var entity = property;
|
var entity = potentialEntity;
|
||||||
var soundProperties = soundEntityMap[entity];
|
var soundProperties = soundEntityMap[entity];
|
||||||
if (soundProperties.needsPlay) {
|
if (soundProperties.readyToPlay) {
|
||||||
print("EBL NEEDS TO PLAY!")
|
print("EBL NEEDS TO PLAY!")
|
||||||
Audio.playSound(soundProperties.sound, {
|
Audio.playSound(soundProperties.sound, {
|
||||||
volume: soundProperties.volume,
|
volume: soundProperties.volume,
|
||||||
position: soundProperties.position,
|
position: soundProperties.position,
|
||||||
loop: soundProperties.loop
|
loop: soundProperties.loop
|
||||||
});
|
});
|
||||||
soundEntityMap[entity].needsPlay = false;
|
soundProperties.readyToPlay = false;
|
||||||
|
} else if(soundProperties.loop === false && soundProperties.interval !==-1) {
|
||||||
|
// We need to check all of our entities that are not looping but have an interval associated with them
|
||||||
|
// to see if it's time for them to play again
|
||||||
|
soundProperties.timeSinceLastPlay += deltaTime;
|
||||||
|
if (soundProperties.timeSinceLastPlay > soundProperties.interval) {
|
||||||
|
print ("EBL TIME TO PLAY AGAIN!");
|
||||||
|
soundProperties.readyToPlay = true;
|
||||||
|
soundProperties.timeSinceLastPlay = 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,8 @@ var userData = {
|
||||||
soundKey: {
|
soundKey: {
|
||||||
url: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove.wav",
|
url: "https://s3-us-west-1.amazonaws.com/hifi-content/eric/Sounds/dove.wav",
|
||||||
volume: 0.2,
|
volume: 0.2,
|
||||||
loop: true
|
loop: false,
|
||||||
|
interval: 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue