1
1
import Judgement from './judgement' ;
2
+ import Timer from './timer' ;
2
3
import { Application , Container , Texture , Sprite , Graphics , Text , Rectangle } from 'pixi.js-legacy' ;
3
4
4
5
const ProgressBarCache = ( ( ) =>
@@ -128,6 +129,7 @@ export default class Game
128
129
this . _watermarkText = params . watermark && params . watermark != '' ? params . watermark : 'github/MisaLiu/phi-chart-render' ;
129
130
130
131
this . _musicId = null ;
132
+ this . _audioTimer = new Timer ( this . _settings . speed ) ;
131
133
this . _audioOffset = 0 ;
132
134
this . _animateStatus = NaN ;
133
135
this . _gameStartTime = NaN ;
@@ -335,6 +337,8 @@ export default class Game
335
337
this . judgement . input . _isPaused = this . _isPaused ;
336
338
337
339
if ( ! this . _musicId ) return ;
340
+
341
+ this . _audioTimer . pause ( ) ;
338
342
if ( this . _isPaused )
339
343
{
340
344
this . chart . music . pause ( ) ;
@@ -352,6 +356,7 @@ export default class Game
352
356
353
357
this . render . ticker . remove ( this . _calcTick ) ;
354
358
this . chart . music . stop ( ) ;
359
+ this . _audioTimer . reset ( ) ;
355
360
this . _musicId = null ;
356
361
357
362
this . chart . reset ( ) ;
@@ -470,13 +475,12 @@ export default class Game
470
475
}
471
476
case 1 :
472
477
{
473
- let currentTime = ( this . chart . music . seek ( ) || 0 ) - this . chart . offset + this . _settings . offset ;
474
- currentTime = currentTime > 0 ? currentTime : 0 ;
478
+ let currentTime = this . _audioTimer . time - this . chart . offset + this . _settings . offset ;
475
479
476
480
this . chart . calcTime ( currentTime ) ;
477
481
if ( ! this . _isPaused ) this . judgement . calcTick ( ) ;
478
482
479
- this . sprites . progressBar . width = ( ( this . chart . music . seek ( ) || 0 ) / this . chart . music . _duration ) * this . render . sizer . width ;
483
+ this . sprites . progressBar . width = ( this . _audioTimer . time / this . chart . music . _duration ) * this . render . sizer . width ;
480
484
break ;
481
485
}
482
486
case 2 :
@@ -527,6 +531,7 @@ export default class Game
527
531
setTimeout ( async ( ) =>
528
532
{
529
533
this . _musicId = this . chart . music . play ( ) ;
534
+ this . _audioTimer . start ( ) ;
530
535
531
536
for ( const judgeline of this . chart . judgelines )
532
537
{
@@ -553,6 +558,7 @@ export default class Game
553
558
this . _isPaused = true ;
554
559
this . _isEnded = true ;
555
560
this . _runCallback ( 'end' ) ;
561
+ this . _audioTimer . reset ( ) ;
556
562
}
557
563
}
558
564
}
0 commit comments