mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 17:03:58 +02:00
Simpler script with sphere to indicate emission point
This commit is contained in:
parent
4cfbc2b11b
commit
4dc929eddb
1 changed files with 33 additions and 18 deletions
|
@ -5,39 +5,54 @@
|
|||
// Created by David Rowe on 5/29/14.
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// This example script plays a sound in a continuous loop.
|
||||
// This example script plays a sound in a continuous loop, and creates a red sphere in front of you at the origin of the sound.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var sound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+A.raw");
|
||||
|
||||
// A few sample files you may want to try:
|
||||
|
||||
//var sound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Guitars/Guitar+-+Nylon+A.raw");
|
||||
//var sound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/220Sine.wav");
|
||||
var sound = new Sound("https://s3-us-west-1.amazonaws.com/highfidelity-public/sounds/Cocktail+Party+Snippets/Bandcamp.wav");
|
||||
|
||||
var soundPlaying = false;
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = Vec3.sum(Camera.getPosition(), Quat.getFront(MyAvatar.orientation));
|
||||
options.volume = 0.5;
|
||||
options.loop = true;
|
||||
var playing = false;
|
||||
var ball = false;
|
||||
|
||||
function keyPressEvent(event) {
|
||||
if (event.text === "1") {
|
||||
if (!Audio.isInjectorPlaying(soundPlaying)) {
|
||||
var options = new AudioInjectionOptions();
|
||||
options.position = MyAvatar.position;
|
||||
options.volume = 0.5;
|
||||
options.loop = true;
|
||||
soundPlaying = Audio.playSound(sound, options);
|
||||
print("Started sound loop");
|
||||
} else {
|
||||
Audio.stopInjector(soundPlaying);
|
||||
print("Stopped sound loop");
|
||||
}
|
||||
function maybePlaySound(deltaTime) {
|
||||
if (sound.downloaded) {
|
||||
var properties = {
|
||||
type: "Sphere",
|
||||
position: options.position,
|
||||
velocity: { x: 0, y: 0, z: 0},
|
||||
gravity: { x: 0, y: 0, z: 0},
|
||||
radius: 0.10,
|
||||
damping: 0.999,
|
||||
color: { red: 200, green: 0, blue: 0 }
|
||||
};
|
||||
ball = Entities.addEntity(properties);
|
||||
soundPlaying = Audio.playSound(sound, options);
|
||||
print("Started sound looping.");
|
||||
Script.update.disconnect(maybePlaySound);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function scriptEnding() {
|
||||
if (Audio.isInjectorPlaying(soundPlaying)) {
|
||||
Audio.stopInjector(soundPlaying);
|
||||
print("Stopped sound loop");
|
||||
Entities.deleteEntity(ball);
|
||||
print("Stopped sound.");
|
||||
}
|
||||
}
|
||||
|
||||
// Connect a call back that happens every frame
|
||||
Script.scriptEnding.connect(scriptEnding);
|
||||
Controller.keyPressEvent.connect(keyPressEvent);
|
||||
Script.update.connect(maybePlaySound);
|
||||
|
||||
|
|
Loading…
Reference in a new issue