File tree Expand file tree Collapse file tree 5 files changed +33
-41
lines changed
Expand file tree Collapse file tree 5 files changed +33
-41
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import * as THREE from "three" ;
2+
3+ export const addAudioListenerToCamera = ( camera ) => {
4+ camera . camera . add ( createAudioListener ( ) ) ;
5+ } ;
6+
7+ const songUrl = require ( "./sounds/bg1.mp3" ) ;
8+ const songUrl1 = require ( "./sounds/tile.mp3" ) ;
9+
10+ export const createAudioListener = ( ) => {
11+ const listener = new THREE . AudioListener ( ) ;
12+
13+ const audioLoader = new THREE . AudioLoader ( ) ;
14+
15+ const sound = new THREE . Audio ( listener ) ;
16+
17+ audioLoader . load ( songUrl , ( buffer ) => {
18+ sound . setBuffer ( buffer ) ;
19+ sound . setLoop ( true ) ;
20+ sound . setVolume ( 0.3 ) ;
21+ sound . play ( ) ;
22+ } ) ;
23+
24+ return listener ;
25+ } ;
26+
27+ export const tile_sound = ( ) => {
28+ const audio = new Audio ( songUrl1 ) ;
29+ audio . play ( ) ;
30+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
1717} from "three" ;
1818import * as THREE from "three" ;
1919import { addAudioListenerToCamera } from "./audio" ;
20- import { addAudioListenerToCamera1 } from "./audio" ;
20+ import { tile_sound } from "./audio" ;
2121
2222import { GameCamera } from "./game-camera" ;
2323import { MovingTile } from "./moving-tile" ;
@@ -65,7 +65,7 @@ export class Game {
6565 this . renderer . domElement . addEventListener ( "click" , this . onClick . bind ( this ) ) ;
6666
6767 this . animate ( ) ;
68- addAudioListenerToCamera ( this . camera ) ; //bg music
68+ addAudioListenerToCamera ( this . camera ) ;
6969
7070 }
7171
@@ -75,7 +75,7 @@ export class Game {
7575 this . cutBox ( ) ;
7676 this . moveUp ( ) ;
7777 this . clicked = false
78- addAudioListenerToCamera1 ( ) ;
78+ tile_sound ( ) ;
7979 }
8080
8181 onWindowResize ( ) {
You can’t perform that action at this time.
0 commit comments