Skip to content

Commit 3597984

Browse files
committed
fix: ensure car engine is available before starting
1 parent 2dfc34a commit 3597984

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/scripts/cars/Car.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ export default class Car {
512512
*/
513513
_createEngineNoise() {
514514
// Create a player for engine noise
515-
this.engine = new Tone.Player("sfx/engine.mp3").toDestination();
516-
// Set volume
517-
this.engine.volume.value = -12;
518-
this.engine.loop = true;
519-
// Connect to gain node to control proximity audio
520-
this.engine.connect(this.gainNode);
521-
this.engine.start();
515+
this.engine = new Tone.Player("sfx/engine.mp3", () => {
516+
// Set volume
517+
this.engine.volume.value = -12;
518+
this.engine.loop = true;
519+
// Connect to gain node to control proximity audio
520+
this.engine.connect(this.gainNode);
521+
}).toDestination();
522522
}
523523

524524
/**

src/scripts/worlds/LivingRoom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ export default class LivingRoom extends World {
140140
// Wait for assets to load before proceeding
141141
const checkLoaded = () => {
142142
if ((this.radio && this.radio.isLoaded) && (this.tv && this.tv.isLoaded)) {
143+
// Start car engine
144+
this.car.engine.start();
143145
this.isLoaded = true;
144146
} else {
145147
requestAnimationFrame(checkLoaded); // Check again in the next frame

src/scripts/worlds/World.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export default class World {
282282
*/
283283
_start() {
284284
this.isLoaded = true;
285+
this.car.engine.start();
285286
}
286287

287288
/**

0 commit comments

Comments
 (0)