Using Sound Entity for the portal

Using Sound Entity for the portal, this simplify the termination of the looping sound.
This commit is contained in:
Alezia Kurdis 2025-01-17 21:23:46 -05:00 committed by GitHub
parent ec47320ee2
commit c70fb31367
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -15,22 +15,15 @@
var portalURL = "";
var portalName = "";
var TP_SOUND = SoundCache.getSound(ROOT + "sounds/teleportSound.mp3");
var PORTAL_SOUND = SoundCache.getSound(ROOT + "sounds/portalSound.mp3");
var portalInjector = Uuid.NONE;
var portalPosition;
this.preload = function(entityID) {
var properties = Entities.getEntityProperties(entityID, ["userData", "dimensions", "position"]);
var properties = Entities.getEntityProperties(entityID, ["userData", "dimensions"]);
var userDataObj = JSON.parse(properties.userData);
portalURL = userDataObj.url;
portalName = userDataObj.name;
portalPosition = properties.position;
var portalColor = getColorFromPlaceID(userDataObj.placeID);
//HERE WE RENDER EFFECT
var textLocalPosition = {"x": 0.0, "y": (properties.dimensions.y / 2) * 1.2, "z": 0.0};
var scale = textLocalPosition.y/1.2;
var textID = Entities.addEntity({
@ -44,7 +37,7 @@
},
"name": portalName,
"text": portalName,
//"textColor": portalColor.saturated,
"textColor": portalColor.light,
"lineHeight": 0.10 * scale,
"backgroundAlpha": 0.0,
"unlit": true,
@ -120,26 +113,18 @@
"spinFinish": 0
},"local");
if (PORTAL_SOUND.downloaded) {
playLoopSound();
} else {
PORTAL_SOUND.ready.connect(onSoundReady);
}
}
function onSoundReady() {
PORTAL_SOUND.ready.disconnect(onSoundReady);
playLoopSound();
}
function playLoopSound() {
var injectorOptions = {
"position": portalPosition,
var loopSoundID = Entities.addEntity({
"type": "Sound",
"parentID": entityID,
"localPosition": {"x": 0.0, "y": 0.0, "z": 0.0},
"name": "PORTAL SOUND",
"soundURL": ROOT + "sounds/portalSound.mp3",
"volume": 0.15,
"loop": true,
"positional": true,
"localOnly": true
};
portalInjector = Audio.playSound(PORTAL_SOUND, injectorOptions);
},"local");
}
this.enterEntity = function(entityID) {
@ -153,16 +138,11 @@
var timer = Script.setTimeout(function () {
Window.location = portalURL;
portalInjector.stop();
Entities.deleteEntity(entityID);
}, 1000);
};
this.unload = function(entityID) {
portalInjector.stop();
};
function getColorFromPlaceID(placeID) {
var idIntegerConstant = getStringScore(placeID);
var hue = (idIntegerConstant%360)/360;