Creating the Scoring Dialog Using Coroutines
If you have come from a background working with Unity, Unreal, or other game engines, you might be familiar with the concept of a coroutine. A coroutine in those contexts is defined much the same way as it is in Babylon.js: a stateful method that runs across multiple frames of rendering.
Though it may imply the presence of multiple threads, typically, in most frameworks (for example, Unity and most certainly JavaScript!), this is not the case. The C# programming language uses Iterators along with the yield keyword to implement coroutines, but in JavaScript, we use a (spoiler alert!) function* generator. Bet no one saw that callback to Chapter 4, Creating the Application coming! Instead of using them as part of our application’s state machine, we’re going to define the logic that will make the score dialog’s scoring entries count upwards from zero, along with playing a cash-register type of sound. Lastly, we’...