RhythmTickMgr.ts 608 B

123456789101112131415161718192021222324
  1. import {GameEventEnum} from "../enum/GameEventEnum";
  2. export default class RhythmTick {
  3. private rhythmTime: number = 0;
  4. private rhythmIndex: number = 0;
  5. private beatInterval: number = 0;
  6. constructor(beatInterval: number) {
  7. this.beatInterval = beatInterval
  8. }
  9. reset() {
  10. this.rhythmTime = 0
  11. this.rhythmIndex = 0
  12. }
  13. rhythmTick(dt: number) {
  14. this.rhythmTime += dt * 1000
  15. if (this.rhythmTime >= this.rhythmIndex * this.beatInterval) {
  16. cc.director.emit(GameEventEnum.RHYTHM_TICK)
  17. this.rhythmIndex++
  18. }
  19. }
  20. }