I am currently developing a space/gravity game using Angular 2, and I am looking to incorporate a splash screen before the main menu component is loaded.
I believe that the easiest approach would be to utilize the pre-bootstrapped contents of the index.html file as shown below:
<body>
<!--
//This is where our bootstrapped content will go.
//Because everything will be removed from the DOM after bootstrap,
//we can consider this pre-bootstrapped index.html as a pseudo "splash screen"
//(animation credit: http://codepen.io/katehummer/pen/zrygBM)
-->
<!--<app-mainmenu>-->
<svg class="solar-system">
<circle id="sun" cx="100" cy="100" r="10" stroke="none" fill="#FFE581" />
<circle id="mercury" cx="100" cy="100" r="3" fill="#fff" stroke="none" />
<circle id="venus" cx="100" cy="100" r="4" fill="#fff" stroke="none" />
<circle id="earth" cx="100" cy="100" r="5" fill="#fff" stroke="none" />
<circle id="mars" cx="100" cy="100" r="5" fill="#fff" stroke="none" />
<circle id="mercury-orbit" cx="100" cy="100" r="35" fill="none" stroke="rgba(255,255,255,0.2)" stroke-width="0.5" />
<circle id="venus-orbit" cx="100" cy="100" r="55" fill="none" stroke="rgba(255,255,255,0.2)" stroke-width="0.5" />
<circle id="earth-orbit" cx="100" cy="100" r="75" fill="none" stroke="rgba(255,255,255,0.2)" stroke-width="0.5" />
<circle id="mars-orbit" cx="100" cy="100" r="95" fill="none" stroke="rgba(255,255,255,0.2)" stroke-width="0.5" />
</svg>
<!--
//WAIT 10 SECONDS MINIMUM - OR WAIT UNTIL USER LOADS IF AFTER 10 SEC
-->
<!--</app-mainmenu>-->
</body>
By commenting out <app-mainmenu>
, I can effectively test my animation, resembling the one indicated in the comments.
The next challenge is to instruct Angular to wait for 10 seconds before bootstrapping. Although I attempted to introduce a delay in JavaScript at the end, it did not work due to its non-blocking nature.
<script>
setInterval(tryFinishLoading, 10000);
function tryFinishLoading() {
alert("loaded");
}
</script>
Can anyone advise me on how to achieve the following:
1) Wait for the user to load, if less than 10 seconds, move to step 2.
2) Hold off until 10 seconds have elapsed, if not loaded, repeat the process until successful loading.
Cheers!