randomized sounds better, made config easier for adding new effects.
This commit is contained in:
parent
9d964cec0e
commit
95899878c7
@ -39,25 +39,25 @@ export class CustomEnvironment {
|
|||||||
window.setTimeout((sound) => {
|
window.setTimeout((sound) => {
|
||||||
sound.play()
|
sound.play()
|
||||||
}, 2000, sounds.background);
|
}, 2000, sounds.background);
|
||||||
const birds: Array<Sound> = [sounds.birds, sounds.dove];
|
const effects: Array<Sound> = sounds.backgroundEffects;
|
||||||
window.setInterval((sounds: Array<Sound>) => {
|
window.setInterval((sounds: Array<Sound>) => {
|
||||||
if (Math.random() < .6) {
|
if (Math.random() < .5) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const sound = Math.floor(Math.random() * sounds.length);
|
const sound = Math.floor(Math.random() * sounds.length);
|
||||||
const x = Math.floor(Math.random() * 20);
|
const x = Math.floor(Math.random() * 20) - 10;
|
||||||
const z = Math.floor(Math.random() * 20);
|
const z = Math.floor(Math.random() * 20) - 10;
|
||||||
|
|
||||||
const position = new Vector3(x, 0, z);
|
const position = new Vector3(x, 0, z);
|
||||||
if (sounds[sound].isPlaying) {
|
if (sounds[sound].isPlaying) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sounds[sound].setPosition(position);
|
sounds[sound].setPosition(position);
|
||||||
sounds[sound].setVolume(Math.random() * .5);
|
sounds[sound].setVolume(Math.random() * .3);
|
||||||
sounds[sound].play();
|
sounds[sound].play();
|
||||||
}
|
}
|
||||||
|
|
||||||
}, 2000, birds);
|
}, 2000, effects);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,8 +3,6 @@ import {Scene, Sound} from "@babylonjs/core";
|
|||||||
export class DiaSounds {
|
export class DiaSounds {
|
||||||
private readonly scene: Scene;
|
private readonly scene: Scene;
|
||||||
|
|
||||||
private readonly _birds: Sound;
|
|
||||||
|
|
||||||
public get tick() {
|
public get tick() {
|
||||||
return new Sound("tick", '/assets/sounds/tick.mp3', this.scene);
|
return new Sound("tick", '/assets/sounds/tick.mp3', this.scene);
|
||||||
}
|
}
|
||||||
@ -53,8 +51,15 @@ export class DiaSounds {
|
|||||||
volume: .5,
|
volume: .5,
|
||||||
loop: false
|
loop: false
|
||||||
}
|
}
|
||||||
this._birds = this.buildSpatialSound("warbler", "/assets/sounds/warbler.mp3");
|
this._backgroundEffects.push(this.buildSpatialSound("warbler2", "/assets/sounds/warbler2.mp3"));
|
||||||
this._dove = this.buildSpatialSound("dove", "/assets/sounds/dove.mp3");
|
this._backgroundEffects.push(this.buildSpatialSound("warbler3", "/assets/sounds/warbler3.mp3"));
|
||||||
|
this._backgroundEffects.push(this.buildSpatialSound("crickets", "/assets/sounds/crickets.mp3"));
|
||||||
|
this._backgroundEffects.push(this.buildSpatialSound("dove", "/assets/sounds/dove.mp3"))
|
||||||
|
}
|
||||||
|
|
||||||
|
_backgroundEffects: Array<Sound> = [];
|
||||||
|
public get backgroundEffects(): Array<Sound> {
|
||||||
|
return this._backgroundEffects;
|
||||||
}
|
}
|
||||||
|
|
||||||
private buildSpatialSound(name: string, url: string) {
|
private buildSpatialSound(name: string, url: string) {
|
||||||
@ -92,15 +97,6 @@ export class DiaSounds {
|
|||||||
return this._low;
|
return this._low;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get birds(): Sound {
|
|
||||||
return this._birds;
|
|
||||||
}
|
|
||||||
|
|
||||||
_dove: Sound;
|
|
||||||
public get dove() {
|
|
||||||
return this._dove;
|
|
||||||
}
|
|
||||||
|
|
||||||
public get bounce() {
|
public get bounce() {
|
||||||
const bounce = this._bounce.clone();
|
const bounce = this._bounce.clone();
|
||||||
bounce.updateOptions({offset: 0, volume: this.volume, length: .990});
|
bounce.updateOptions({offset: 0, volume: this.volume, length: .990});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user