I have a component that has a scorebar on the left side. I also have a game service that handles all game logic. If a new player joins, I want to hide the scorebar, change the players array within the game.service and show the scorebar again.
This is what I currently have:
game.component.ts:
this.scorebarSub = this.gameService.hideScorebar.subscribe(hide => {
const scorebar = $('#score-bar');
if (hide && !this.scoreIsHidden) {
scorebar.animate({"margin-left": '-=400'});
this.scoreIsHidden = true;
} else if (!hide && this.scoreIsHidden) {
scorebar.animate({"margin-left": '+=400'});
this.scoreIsHidden = false;
}
})
game.service.ts:
playerJoined(player: Player) {
this.hideScorebar.next(true);
this.currentRoom.players.push(player);
this.hideScorebar.next(false);
}
The problem is now that I cant wait for the animation to finish so the scorebar gets updated while the hide animation is played.
How can I do this in a better way?