summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-09-11 17:25:21 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-09-11 17:25:21 +0200
commit315120c2eb21ebe415da10d7bc16ea513033a79a (patch)
tree05649c248628d7b2a40e14ad9281fcf14593cfe4
parent914d41346ad0167dd497d05ff0dbac7726d00537 (diff)
downloadRustAndDust-315120c2eb21ebe415da10d7bc16ea513033a79a.zip
RustAndDust-315120c2eb21ebe415da10d7bc16ea513033a79a.tar.gz
add screens/LoadScreen + actors/LoadingBar + assets
-rw-r--r--android/assets/loading.pack96
-rw-r--r--android/assets/loading.pngbin0 -> 132376 bytes
-rw-r--r--core/src/ch/asynk/tankontank/TankOnTank.java2
-rw-r--r--core/src/ch/asynk/tankontank/actors/LoadingBar.java32
-rw-r--r--core/src/ch/asynk/tankontank/screens/LoadScreen.java153
5 files changed, 282 insertions, 1 deletions
diff --git a/android/assets/loading.pack b/android/assets/loading.pack
new file mode 100644
index 0000000..b6e52a4
--- /dev/null
+++ b/android/assets/loading.pack
@@ -0,0 +1,96 @@
+
+loading.png
+format: RGBA8888
+filter: Nearest,Nearest
+repeat: none
+loading-frame
+ rotate: false
+ xy: 1, 435
+ size: 540, 60
+ orig: 540, 60
+ offset: 0, 0
+ index: -1
+loading-bar-anim
+ rotate: false
+ xy: 1, 384
+ size: 501, 49
+ orig: 501, 49
+ offset: 0, 0
+ index: 1
+loading-bar-anim
+ rotate: false
+ xy: 1, 333
+ size: 501, 49
+ orig: 501, 49
+ offset: 0, 0
+ index: 2
+loading-bar-anim
+ rotate: false
+ xy: 1, 282
+ size: 501, 49
+ orig: 501, 49
+ offset: 0, 0
+ index: 3
+loading-bar-anim
+ rotate: false
+ xy: 1, 231
+ size: 501, 49
+ orig: 501, 49
+ offset: 0, 0
+ index: 4
+loading-bar-anim
+ rotate: false
+ xy: 1, 180
+ size: 501, 49
+ orig: 501, 49
+ offset: 0, 0
+ index: 5
+loading-bar1
+ rotate: false
+ xy: 1, 129
+ size: 501, 49
+ orig: 501, 49
+ offset: 0, 0
+ index: -1
+loading-bar2
+ rotate: false
+ xy: 1, 78
+ size: 501, 49
+ orig: 501, 49
+ offset: 0, 0
+ index: -1
+libgdx-logo
+ rotate: false
+ xy: 1, 8
+ size: 408, 68
+ orig: 408, 68
+ offset: 0, 0
+ index: -1
+tank-logo
+ rotate: false
+ xy: 503, 77
+ size: 249, 299
+ orig: 249, 299
+ offset: 0, 0
+ index: -1
+loading-bar-hidden
+ rotate: false
+ xy: 543, 441
+ size: 33, 54
+ orig: 33, 54
+ offset: 0, 0
+ index: -1
+loading-frame-bg
+ rotate: false
+ xy: 504, 428
+ size: 5, 5
+ orig: 5, 5
+ offset: 0, 0
+ index: -1
+screen-bg
+ rotate: false
+ xy: 1, 1
+ size: 5, 5
+ orig: 5, 5
+ offset: 0, 0
+ index: -1
diff --git a/android/assets/loading.png b/android/assets/loading.png
new file mode 100644
index 0000000..96c4d21
--- /dev/null
+++ b/android/assets/loading.png
Binary files differ
diff --git a/core/src/ch/asynk/tankontank/TankOnTank.java b/core/src/ch/asynk/tankontank/TankOnTank.java
index 90a3068..18f2e16 100644
--- a/core/src/ch/asynk/tankontank/TankOnTank.java
+++ b/core/src/ch/asynk/tankontank/TankOnTank.java
@@ -19,7 +19,7 @@ public class TankOnTank extends Game
manager = new AssetManager();
- // this.setScreen(new LoadScreen(this));
+ this.setScreen(new LoadScreen(this));
}
public void loadAssets()
diff --git a/core/src/ch/asynk/tankontank/actors/LoadingBar.java b/core/src/ch/asynk/tankontank/actors/LoadingBar.java
new file mode 100644
index 0000000..c8b138f
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/actors/LoadingBar.java
@@ -0,0 +1,32 @@
+package ch.asynk.tankontank.actors;
+
+import com.badlogic.gdx.graphics.g2d.Animation;
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.TextureRegion;
+import com.badlogic.gdx.scenes.scene2d.Actor;
+
+public class LoadingBar extends Actor
+{
+ Animation animation;
+ TextureRegion reg;
+ float stateTime;
+
+ public LoadingBar(Animation animation)
+ {
+ this.animation = animation;
+ reg = animation.getKeyFrame(0);
+ }
+
+ @Override
+ public void act(float delta)
+ {
+ stateTime += delta;
+ reg = animation.getKeyFrame(stateTime);
+ }
+
+ @Override
+ public void draw(Batch batch, float parentAlpha)
+ {
+ batch.draw(reg, getX(), getY());
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/screens/LoadScreen.java b/core/src/ch/asynk/tankontank/screens/LoadScreen.java
new file mode 100644
index 0000000..1ac8959
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/screens/LoadScreen.java
@@ -0,0 +1,153 @@
+package ch.asynk.tankontank.screens;
+
+import com.badlogic.gdx.Gdx;
+import com.badlogic.gdx.Screen;
+import com.badlogic.gdx.graphics.GL20;
+import com.badlogic.gdx.graphics.g2d.Animation;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.math.Interpolation;
+import com.badlogic.gdx.scenes.scene2d.Actor;
+import com.badlogic.gdx.scenes.scene2d.Stage;
+import com.badlogic.gdx.scenes.scene2d.ui.Image;
+import com.badlogic.gdx.utils.viewport.FitViewport;
+
+import ch.asynk.tankontank.TankOnTank;
+import ch.asynk.tankontank.actors.LoadingBar;
+
+public class LoadScreen extends AbstractScreen
+{
+ private Stage stage;
+
+ private Image logo;
+ private Image loadingFrame;
+ private Image loadingBarHidden;
+ private Image screenBg;
+ private Image loadingBg;
+
+ private final int loadingBgWidth = 450;
+ private float startX, endX;
+ private float percent;
+
+ private Actor loadingBar;
+
+ private float delay = 0.0f;
+
+ public LoadScreen(final TankOnTank game)
+ {
+ super(game);
+ }
+
+ @Override
+ public void render(float delta)
+ {
+ Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
+
+ if (game.manager.update()) {
+ if (delay < 1.0f) {
+ delay += delta;
+ if (delay >= 1.0f) {
+ Gdx.app.debug("LoadScreen", "assets loaded : " + (Gdx.app.getJavaHeap()/1024.0f) + "KB");
+ // game.setScreen(new GameScreen(game));
+ // dispose();
+ }
+ }
+ }
+
+ percent = Interpolation.linear.apply(percent, game.manager.getProgress(), 0.1f);
+
+ loadingBarHidden.setX(startX + endX * percent);
+ loadingBg.setX(loadingBarHidden.getX() + 30);
+ loadingBg.setWidth(loadingBgWidth - loadingBgWidth * percent);
+ loadingBg.invalidate();
+
+ stage.act();
+ stage.draw();
+ }
+
+ @Override
+ public void show()
+ {
+ Gdx.app.debug("LoadScreen", "show()");
+ game.manager.load("loading.pack", TextureAtlas.class);
+ game.manager.finishLoading();
+
+ stage = new Stage(new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
+
+ TextureAtlas atlas = game.manager.get("loading.pack", TextureAtlas.class);
+
+ // logo = new Image(atlas.findRegion("libgdx-logo"));
+ logo = new Image(atlas.findRegion("tank-logo"));
+ loadingFrame = new Image(atlas.findRegion("loading-frame"));
+ loadingBarHidden = new Image(atlas.findRegion("loading-bar-hidden"));
+ screenBg = new Image(atlas.findRegion("screen-bg"));
+ loadingBg = new Image(atlas.findRegion("loading-frame-bg"));
+
+ Animation anim = new Animation(0.05f, atlas.findRegions("loading-bar-anim") );
+ anim.setPlayMode(Animation.PlayMode.LOOP_REVERSED);
+ loadingBar = new LoadingBar(anim);
+ // loadingBar = new Image(atlas.findRegion("loading-bar1"));
+
+ stage.addActor(screenBg);
+ stage.addActor(logo);
+ stage.addActor(loadingBar);
+ stage.addActor(loadingBg);
+ stage.addActor(loadingBarHidden);
+ stage.addActor(loadingFrame);
+
+ game.loadAssets();
+ }
+
+ @Override
+ public void resize(int width, int height)
+ {
+ Gdx.app.debug("LoadScreen", "resize (" + width + "," + height + ")");
+
+ stage.getViewport().update(width, height, true);
+
+ screenBg.setSize(stage.getWidth(), stage.getHeight());
+
+ logo.setX((stage.getWidth() - logo.getWidth()) / 2);
+ logo.setY((stage.getHeight() - logo.getHeight()) - 50);
+
+ loadingFrame.setX((stage.getWidth() - loadingFrame.getWidth()) / 2);
+ loadingFrame.setY(logo.getY() - loadingFrame.getHeight() - 20);
+
+ loadingBar.setX(loadingFrame.getX() + 15);
+ loadingBar.setY(loadingFrame.getY() + 5);
+
+ loadingBarHidden.setX(loadingBar.getX() + 35);
+ loadingBarHidden.setY(loadingBar.getY() - 3);
+ startX = loadingBarHidden.getX();
+ endX = loadingBgWidth - 10;
+
+ loadingBg.setSize(loadingBgWidth, 50);
+ loadingBg.setX(loadingBarHidden.getX() + 30);
+ loadingBg.setY(loadingBarHidden.getY() + 3);
+ }
+
+ @Override
+ public void dispose()
+ {
+ Gdx.app.debug("LoadScreen", "dispose()");
+ stage.dispose();
+ }
+
+ @Override
+ public void hide()
+ {
+ Gdx.app.debug("LoadScreen", "hide()");
+ game.manager.unload("loading.pack");
+ }
+
+ @Override
+ public void pause()
+ {
+ Gdx.app.debug("LoadScreen", "pause()");
+ }
+
+ @Override
+ public void resume()
+ {
+ Gdx.app.debug("LoadScreen", "resume()");
+ }
+}