play song during victory
This commit is contained in:
@@ -13,7 +13,8 @@ AFRAME.registerComponent('song', {
|
||||
challengeId: {default: ''},
|
||||
isBeatsPreloaded: {default: false},
|
||||
isGameOver: {default: false},
|
||||
isPlaying: {default: false}
|
||||
isPlaying: {default: false},
|
||||
isVictory: {default: false}
|
||||
},
|
||||
|
||||
init: function () {
|
||||
@@ -30,6 +31,14 @@ AFRAME.registerComponent('song', {
|
||||
this.el.addEventListener('gamemenurestart', this.onRestart.bind(this));
|
||||
this.el.addEventListener('wallhitstart', this.onWallHitStart.bind(this));
|
||||
this.el.addEventListener('wallhitend', this.onWallHitEnd.bind(this));
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
this.el.addEventListener('fakevictory', () => {
|
||||
this.source.stop();
|
||||
this.source.disconnect();
|
||||
this.victory();
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
update: function (oldData) {
|
||||
@@ -45,6 +54,20 @@ AFRAME.registerComponent('song', {
|
||||
this.audioAnalyser.gainNode.value = BASE_VOLUME;
|
||||
}
|
||||
|
||||
// On victory screen, play song in background.
|
||||
if (!oldData.isVictory && data.isVictory) {
|
||||
this.data.analyserEl.addEventListener('audioanalyserbuffersource', evt => {
|
||||
this.audioAnalyser.resumeContext();
|
||||
const gain = this.audioAnalyser.gainNode.gain;
|
||||
gain.cancelScheduledValues(0);
|
||||
gain.setValueAtTime(0.05, 0);
|
||||
this.source = evt.detail;
|
||||
this.source.start();
|
||||
}, ONCE);
|
||||
this.audioAnalyser.refreshSource();
|
||||
return;
|
||||
}
|
||||
|
||||
// New challenge, play if we have loaded and were waiting for beats to preload.
|
||||
if (!oldData.isBeatsPreloaded && this.data.isBeatsPreloaded && this.source) {
|
||||
this.startAudio();
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
bind__gameover="isGameOver: isGameOver"
|
||||
bind__intro-song="isPlaying: menuActive && !menuSelectedChallenge.id; isSearching: isSearching"
|
||||
bind__overlay="enabled: !isPlaying"
|
||||
bind__song="challengeId: challenge.id; isPlaying: isPlaying; isBeatsPreloaded: challenge.isBeatsPreloaded; isGameOver: isGameOver"
|
||||
bind__song="challengeId: challenge.id; isPlaying: isPlaying; isBeatsPreloaded: challenge.isBeatsPreloaded; isGameOver: isGameOver; isVictory: isVictory"
|
||||
bind__song-preview-system="challengeId: challenge.id; isSearching: isSearching; isSongLoading: isSongLoading; selectedChallengeId: menuSelectedChallenge.id"
|
||||
animation__gameover="property: object3D.background; type: color; to: #750000; startEvents: gameover"
|
||||
animation__gameoverfog="property: components.fog.el.object3D.fog.color; type: color; to: #330000; startEvents: gameover; dur: 500; easing: easeInQuad"
|
||||
|
||||
Reference in New Issue
Block a user