From 7fad3866f825567984dfe60cb75c2ccdb3fcd4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 27 Jun 2018 10:27:33 +0200 Subject: LoadingScreen : clean up, count blinks after isLoaded --- .../ch/asynk/zproject/screens/LoadingScreen.java | 39 ++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/core/src/ch/asynk/zproject/screens/LoadingScreen.java b/core/src/ch/asynk/zproject/screens/LoadingScreen.java index 154cc11..598beb9 100644 --- a/core/src/ch/asynk/zproject/screens/LoadingScreen.java +++ b/core/src/ch/asynk/zproject/screens/LoadingScreen.java @@ -18,7 +18,7 @@ public class LoadingScreen implements Screen private final Color c; private final OrthographicCamera camera; - private final float DELAY_AFTER = 1f; + private final float BLINK_AFTER = 2f; private final float ALPHA_FACTOR = 1.5f; private boolean paused; @@ -29,7 +29,7 @@ public class LoadingScreen implements Screen private AtlasRegion loaded; private int x, y; - private float acc; + private int count; private float percent; private float alpha; private boolean incr; @@ -75,29 +75,33 @@ public class LoadingScreen implements Screen { if (paused) return; - percent = zproject.assets.getProgress(); + if (!isLoaded) { + if (zproject.assets.update()) { + ZProject.debug("LoadingScreen", "assets loaded"); + isLoaded = true; + percent = 1f; + } else { + percent = zproject.assets.getProgress(); + } + } + if (!isLoaded && percent >= 1f) { - acc = 0f; + count = 0; alpha = 1f; incr = false; } - if (isLoaded) { - acc += delta; - if (acc >= DELAY_AFTER) { - // FIXME callback - // zproject.switchToGame(); - onLoaded.call(); - return; - } - } - delta *= ALPHA_FACTOR; if (incr) { alpha += delta; if (alpha >= 1f ) { alpha = 1f; incr = false; + if (isLoaded) count += 1; + if (count >= BLINK_AFTER) { + onLoaded.call(); + return; + } } } else { alpha -= delta; @@ -107,13 +111,6 @@ public class LoadingScreen implements Screen } } - if (!isLoaded) { - if (zproject.assets.update()) { - ZProject.debug("LoadingScreen", "assets loaded"); - isLoaded = true; - } - } - Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); -- cgit v1.1-2-g2b99