Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.nizarium.mygame;
- import android.os.Handler.Callback;
- import android.os.Message;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.Input.Keys;
- import com.badlogic.gdx.files.FileHandle;
- import com.badlogic.gdx.graphics.Pixmap;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.TextureData;
- import com.badlogic.gdx.graphics.Pixmap.Format;
- import com.badlogic.gdx.graphics.TextureData.TextureDataType;
- import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
- import com.badlogic.gdx.graphics.g2d.SpriteBatch;
- import com.badlogic.gdx.scenes.scene2d.Actor;
- import com.badlogic.gdx.scenes.scene2d.Stage;
- public class StageLoading extends GameStage
- {
- private Callback onLoaded;
- public StageLoading(float width, float height, boolean stretch,
- GameMain main)
- {
- super(width, height, stretch, main);
- init();
- }
- private void init()
- {
- Pixmap blankPixmap = new Pixmap(1, 1, Format.RGBA8888);
- blankPixmap.setColor(1, 1, 1, 1);
- blankPixmap.drawPixel(0, 0);
- final Texture blank = new Texture(blankPixmap);
- this.addActor(new Actor("background")
- {
- @Override
- public Actor hit(float x, float y)
- {
- return null;
- }
- @Override
- public void draw(SpriteBatch batch, float parentAlpha)
- {
- final String loadingStr = "Loading";
- batch.draw(main.getGuiBackground(),
- this.getStage().centerX() - main.getGuiBackground().getWidth()
- * 0.5f,
- this.getStage().centerY() - main.getGuiBackground().getHeight()
- * 0.5f, main.getGuiBackground().getWidth(),
- main.getGuiBackground().getHeight(), 0, 0, 1, 1);
- TextBounds bounds = main.getFont().getBounds(loadingStr);
- main.getFont().draw(batch, loadingStr,
- this.getStage().centerX() - bounds.width * 0.5f,
- this.getStage().centerY() - bounds.height);
- batch.draw(blank, 0, height() - 5, width() * main.getManager().getProgress(), 5);
- }
- });
- }
- @Override
- public void act(float delta)
- {
- super.act(delta);
- if (main.getManager().getProgress() == 1)
- {
- for (GameData.ObjectTypeData data : GameData.objects.values())
- {
- data.init(main);
- }
- if (onLoaded != null)
- onLoaded.handleMessage(new Message());
- }
- }
- @Override
- public boolean keyDown(int keycode)
- {
- if (keycode == Keys.BACK)
- {
- System.exit(0);
- return true;
- }
- return super.keyDown(keycode);
- }
- public Callback getOnLoaded()
- {
- return onLoaded;
- }
- public void setOnLoaded(Callback onLoaded)
- {
- this.onLoaded = onLoaded;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement