diff --git a/src/Music.ts b/src/Music.ts index d1ec5a5..b456041 100644 --- a/src/Music.ts +++ b/src/Music.ts @@ -106,9 +106,9 @@ export class Music { const { audio, isPlaying } = this; const genTime = audio.currentTime; - this.deltaTime = genTime - this.__prevAudioTime; if ( isPlaying ) { + this.deltaTime = genTime - this.__prevAudioTime; this.time += this.deltaTime; const buffer = this.__bufferPool.next(); @@ -125,6 +125,8 @@ export class Music { bufferSource.start( audio.currentTime, audio.currentTime - genTime ); this.__prevBufferSource = bufferSource; } else { + this.deltaTime = 0.0; + this.__prevBufferSource?.stop( audio.currentTime ); this.__prevBufferSource = null; } diff --git a/src/entities/Cube.ts b/src/entities/Cube.ts index 95dc640..23dcb1a 100644 --- a/src/entities/Cube.ts +++ b/src/entities/Cube.ts @@ -17,13 +17,15 @@ export class Cube { public constructor() { this.entity = new Entity(); - this.entity.transform.rotation = Quaternion.fromAxisAngle( + const rot0 = Quaternion.fromAxisAngle( new Vector3( [ 1.0, 0.0, 0.0 ] ), 0.4, ).multiply( Quaternion.fromAxisAngle( new Vector3( [ 0.0, 0.0, 1.0 ] ), 0.4, ) ); + + this.entity.transform.rotation = rot0; this.entity.transform.scale = this.entity.transform.scale.scale( 0.8 ); this.geometry = this.__createGeometry(); @@ -37,9 +39,9 @@ export class Cube { this.entity.components.push( this.mesh ); this.entity.components.push( new Lambda( { - onUpdate: ( { deltaTime } ) => { - this.entity.transform.rotation = this.entity.transform.rotation.multiply( - Quaternion.fromAxisAngle( new Vector3( [ 0.0, 1.0, 0.0 ] ), deltaTime ) + onUpdate: ( { time } ) => { + this.entity.transform.rotation = rot0.multiply( + Quaternion.fromAxisAngle( new Vector3( [ 0.0, 1.0, 0.0 ] ), time ) ); }, visible: false,