Example usage for com.badlogic.gdx Game setScreen

List of usage examples for com.badlogic.gdx Game setScreen

Introduction

In this page you can find the example usage for com.badlogic.gdx Game setScreen.

Prototype

public void setScreen(Screen screen) 

Source Link

Document

Sets the current screen.

Usage

From source file:ac.uk.dmu.ash.game.screen.CreditsScreen.java

License:Open Source License

/**
 * Creates a new {@link CreditsScreen}./*  w  w w  .  j a  v  a  2s  .  co  m*/
 * @param game The game instance.
 * @param assets The game assets
 */
public CreditsScreen(final Game game, final AssetManager assets) {
    this.assets = assets;

    Gdx.input.setInputProcessor(stage);

    Table fpsTable = createTableWithLabel(assets, "ui_skin", Align.left, (Align.top | Align.left), "fps:");
    fpsLabel = (Label) fpsTable.getCells().get(0).getWidget();
    stage.addActor(fpsTable);

    Table creditsTable = createTableWithLabel(assets, "ui_skin", CREDITS);
    stage.addActor(creditsTable);

    TextButton backButton = createTextButton(assets, "ui_skin", "Back", new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            dispose();
            game.setScreen(new MainMenuScreen(game, assets));
        }
    });

    Table buttonsTable = createTable(Align.left | Align.bottom);
    buttonsTable.add(backButton);
    stage.addActor(buttonsTable);
}

From source file:ateamproject.kezuino.com.github.render.screens.ClanGamesScreen.java

public ClanGamesScreen(Game game) {
    super(game);/*from  w  ww . jav  a  2  s .c  om*/

    Table table = new Table();

    for (int i = 0; i < 5; i++) {
        Label clan = new Label("OurClan", skin);
        Label clanjoin = new Label("8/10", skin);

        table.add(clan);
        table.add(clanjoin);
        table.row();
    }

    TextButton btnBack = new TextButton("< Back", skin);
    btnBack.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(new MainScreen(game));
        }
    });
    btnBack.setSize(300, 400);

    table.add(btnBack).colspan(2);

    table.setPosition(stage.getWidth() / 2, stage.getHeight() / 2);

    //stage.addActor(btnLogin);        
    stage.addActor(table);

    backgroundMusic = Assets.getMusicStream("menu.mp3");
}

From source file:ateamproject.kezuino.com.github.render.screens.CreditsScreen.java

public CreditsScreen(Game game) {
    super(game);/*ww  w.j  ava2  s.  co  m*/
    this.maxNumberOfModifieingThreadsRandom = 40;
    this.maxNumberOfModifieingThreadsRow = 1;

    this.numberOfModifieingThreadsRow = new AtomicInteger(0);
    this.numberOfModifieingThreadsRandom = new AtomicInteger(0);

    content = new ArrayList<>();
    titelLabels = new ArrayList<>();
    contentLabels = new ArrayList<>();
    titelLabelsModified = new CopyOnWriteArrayList<>();
    contentLabelsModified = new CopyOnWriteArrayList<>();

    this.titel = "The A - Team";
    content.add("* Lead developer: Fatih Taskent*,");
    content.add("* Logic/Netcode: Anton van Dijk*,");
    content.add("* Logic/Clansystem: Jip van de Vijfeijke*,");
    content.add("* Logic/Syncing: Ken van de Linde*,");
    content.add("* Graphics/Testing: David Vlijmincx*,");
    content.add("* Documentation/Support: Sven Keunen*");

    backgroundMusic = Assets.getMusicStream("credits.mp3");
    backgroundMusic.setPosition(0);
    clearOnRenderColor = Color.BLACK;

    titelFont = new Label.LabelStyle(new BitmapFont(Gdx.files.internal("fonts/credits.fnt"),
            Gdx.files.internal("fonts/credits_0.png"), false), Color.BLUE);
    contentFont = new Label.LabelStyle(new BitmapFont(Gdx.files.internal("fonts/credits.fnt"),
            Gdx.files.internal("fonts/credits_0.png"), false), Color.WHITE);

    rand = new Random();

    Image i = new Image(new Texture("gui/credits.png"));
    i.setFillParent(true);
    stage.addActor(i);

    final Thread head = Thread.currentThread();

    TextButton exit = new TextButton("", skin);
    exit.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            head.interrupt();
            game.setScreen(new MainScreen(game));
        }
    });
    exit.setColor(Color.DARK_GRAY);
    exit.setPosition(stage.getWidth() - 35, stage.getHeight() - 30);
    stage.addActor(exit);

    createLabels();
    placeLabels();
    modifyLabels();
}

From source file:ateamproject.kezuino.com.github.render.screens.GameOverScreen.java

public GameOverScreen(Game game, Score score) {
    super(game);/*from  w  w  w .j  a v a2  s .  c o  m*/

    TextButton btnBack = new TextButton("Stoppen", skin);
    TextButton btnRetry = new TextButton("Opnieuw proberen", skin);
    Label lblEndGameText = new Label("Game Over\nJe score was:", skin);
    Label lblScore = new Label(Integer.toString(score.valueOf()), skin);
    btnBack.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Client.getInstance().send(new PacketKick(PacketKick.KickReasonType.GAME, "Left game.", null));
            game.setScreen(new MainScreen(game));
        }
    });
    btnRetry.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Client.getInstance().send(new PacketLaunchGame(false, null));
            game.setScreen(new GameScreen(game));
        }
    });

    lblEndGameText.setPosition(stage.getWidth() / 2 - lblEndGameText.getWidth() / 2, stage.getHeight() - 50);
    lblScore.setPosition(stage.getWidth() / 2 - lblScore.getWidth() / 2, stage.getHeight() - 80);
    btnRetry.setSize(200, 40);
    btnBack.setSize(200, 40);
    btnRetry.setPosition((stage.getWidth() / 2) - (btnRetry.getWidth() / 2) + (btnBack.getWidth() / 2) + 5,
            stage.getHeight() / 4 - btnRetry.getHeight() / 2);
    btnBack.setPosition((stage.getWidth() / 2) - (btnBack.getWidth() / 2) - (btnRetry.getWidth() / 2) - 5,
            stage.getHeight() / 4 - btnBack.getHeight() / 2);

    if (Client.getInstance().isHost()) {
        stage.addActor(btnRetry);
    }
    stage.addActor(btnBack);
    stage.addActor(lblEndGameText);
    stage.addActor(lblScore);

    backgroundMusic = Assets.getMusicStream("menu.mp3");
}

From source file:ateamproject.kezuino.com.github.render.screens.HighscoreScreen.java

public HighscoreScreen(Game game, boolean top10HighscoreReached) {
    super(game);/*  w w w. j  a  va 2  s. c  om*/

    TextButton btnBack = new TextButton("Terug", skin);
    btnBack.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (top10HighscoreReached) {
                game.setScreen(new CreditsScreen(game));
            } else {
                game.setScreen(new MainScreen(game));
            }
        }
    });
    float x = 240;
    float y = stage.getHeight() / 4;
    btnBack.setSize(200, 40);
    btnBack.setPosition(stage.getWidth() / 2 - btnBack.getWidth() / 2,
            stage.getHeight() / 4 - btnBack.getHeight() / 2);

    Label lblTitle = new Label("Highscore", skin);
    if (top10HighscoreReached) {
        lblTitle = new Label("Gefeliciteerd met een top 10 plek!", skin);
        btnBack.setText("Haal mijn prijs op");
    }
    lblTitle.setColor(Color.YELLOW);
    lblTitle.setPosition(stage.getWidth() / 2 - lblTitle.getWidth() / 2, stage.getHeight() - 50);

    PacketGetHighscores packet = new PacketGetHighscores(Client.getInstance().getId());
    Client.getInstance().send(packet);

    Table table = new Table();
    table.setSkin(skin);

    int rankNr = 0;

    for (Map.Entry<String, Integer> entry : packet.getResult().entrySet()) {
        rankNr++;
        table.add(new Label(Integer.toString(rankNr), skin)).padRight(50);
        table.add(new Label(entry.getKey(), skin)).padRight(50);
        table.add(new Label(Integer.toString(entry.getValue()), skin));
        table.row();
    }

    table.setPosition(stage.getWidth() / 2 - table.getWidth() / 2, stage.getHeight() - 190);

    stage.addActor(btnBack);
    stage.addActor(lblTitle);
    stage.addActor(table);

    backgroundMusic = Assets.getMusicStream("menu.mp3");
}

From source file:ateamproject.kezuino.com.github.render.screens.LoginScreen.java

public LoginScreen(Game game) {
    super(game);//w  w  w .  java  2  s . c  o  m

    TextField txtUsername = new TextField("pactales1@gmail.com", skin);

    TextField txtPassword = new TextField("pactales!", skin);
    txtPassword.setPasswordCharacter('*');
    txtPassword.setPasswordMode(true);

    TextButton btnLogin = new TextButton("Inloggen", skin);

    btnLogin.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            btnLogin.setTouchable(Touchable.disabled);
            btnLogin.setText("Laden");
            Thread loginThread = new Thread(() -> {
                PacketLoginAuthenticate packet = new PacketLoginAuthenticate(txtUsername.getText(),
                        txtPassword.getText(), null);
                Client.getInstance().send(packet);

                Gdx.app.postRunnable(() -> {
                    // Login was successful..
                    if (Client.getInstance().getId() != null) {
                        PacketLoginUserExists packetUserExists = new PacketLoginUserExists(
                                txtUsername.getText(), null);
                        Client.getInstance().send(packetUserExists);

                        // Handle user doesn't exist.
                        if (!packetUserExists.getResult()) {
                            Dialog d = new Dialog("Geen gebruiker gevonden", skin);
                            d.add("Gebruikersnaam:");
                            TextField f = new TextField("", skin);
                            d.add(f);
                            bExit = new TextButton("Oke", skin);
                            bExit.addListener(new ClickListener() {
                                @Override
                                public void clicked(InputEvent event, float x, float y) {
                                    if (!f.getText().isEmpty()) {
                                        PacketLoginCreateNewUser packet1;
                                        packet1 = new PacketLoginCreateNewUser(f.getText(),
                                                txtUsername.getText());
                                        Client.getInstance().send(packet1);
                                        if (!packet1.getResult()) {
                                            new Dialog("Error", skin) {
                                                {
                                                    text("De naam bestaat al.");
                                                    button("Oke");
                                                }
                                            }.show(stage);
                                        } else {
                                            d.hide();
                                            Client.getInstance().setUsername(f.getText());
                                            game.setScreen(new MainScreen(game));
                                        }
                                    }
                                }
                            });
                            d.add(bExit);
                            d.show(stage);
                        } else {
                            game.setScreen(new MainScreen(game));
                        }
                    } else {
                        new Dialog("Error", skin) {
                            {
                                text(packet.getResult().getMessage());
                                button("Oke");
                            }
                        }.show(stage);
                    }
                    btnLogin.setText("Inloggen");
                    btnLogin.setTouchable(Touchable.enabled);//enable button touch
                });
            });
            loginThread.start();
        }
    });

    txtUsername.setSize(300, 40);
    txtPassword.setSize(300, 40);
    txtPassword.setPasswordMode(true);
    btnLogin.setSize(300, 40);

    btnLogin.setPosition(stage.getWidth() / 2 - btnLogin.getWidth() / 2, 150);
    txtUsername.setPosition(stage.getWidth() / 2 - txtUsername.getWidth() / 2, 300);
    txtPassword.setPosition(stage.getWidth() / 2 - txtPassword.getWidth() / 2, 250);

    stage.addActor(btnLogin);
    stage.addActor(txtUsername);
    stage.addActor(txtPassword);

    backgroundMusic = Assets.getMusicStream("menu.mp3");
}

From source file:ateamproject.kezuino.com.github.render.screens.MainScreen.java

public MainScreen(Game game) {
    super(game);//from   w w  w.j  av a2 s.com

    TextButton tbSearchGame = new TextButton("Spel zoeken", skin);
    tbSearchGame.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(new LobbyListScreen(game, false));
        }
    });

    TextButton tbClanGame = new TextButton("Clan spel", skin);
    tbClanGame.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            Client client = Client.getInstance();
            PacketGetClans packet = new PacketGetClans();

            client.send(packet);
            ArrayList<String> listclans = packet.getResult();

            if (listclans.isEmpty()) {
                Dialog d = new Dialog("error", skin);
                d.add("Gebruiker zit niet in een clan.");
                TextButton bExit = new TextButton("Oke", skin);
                bExit.addListener(new ClickListener() {
                    @Override
                    public void clicked(InputEvent event, float x, float y) {
                        d.hide();
                    }
                });
                d.add(bExit);
                d.show(stage);
            } else {
                game.setScreen(new LobbyListScreen(game, true));
            }
        }
    });

    TextButton tbHighscores = new TextButton("Highscores", skin);
    tbHighscores.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(new HighscoreScreen(game, false));
        }
    });

    TextButton tbChangeLook = new TextButton("Uiterlijk aanpassen", skin);
    tbChangeLook.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(new SkinSelectScreen(game));

        }
    });

    TextButton tbLogout = new TextButton("Uitloggen", skin);
    tbLogout.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            PacketKick packet = new PacketKick(PacketKick.KickReasonType.QUIT, "Logging out.", null);
            Client.getInstance().send(packet);
            game.setScreen(new LoginScreen(game));
        }
    });

    TextButton tbClanManagement = new TextButton("Clan management", skin);
    tbClanManagement.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(new ClanManagementScreen(game));
        }
    });

    tbChangeLook.setSize(300, 40);
    tbClanGame.setSize(300, 40);
    tbHighscores.setSize(300, 40);
    tbLogout.setSize(300, 40);
    tbSearchGame.setSize(300, 40);
    tbClanManagement.setSize(300, 40);

    float xOfSearchGameButton = stage.getWidth() / 2 - tbSearchGame.getWidth() / 2;
    float yOfSearchGameButton = stage.getHeight() - 50;

    tbSearchGame.setPosition(xOfSearchGameButton, yOfSearchGameButton);
    tbClanGame.setPosition(xOfSearchGameButton, yOfSearchGameButton - 50);
    tbHighscores.setPosition(xOfSearchGameButton, yOfSearchGameButton - 100);
    tbChangeLook.setPosition(xOfSearchGameButton, yOfSearchGameButton - 150);
    tbClanManagement.setPosition(xOfSearchGameButton, yOfSearchGameButton - 200);
    tbLogout.setPosition(xOfSearchGameButton, yOfSearchGameButton - 250);

    stage.addActor(tbSearchGame);
    stage.addActor(tbClanGame);
    stage.addActor(tbHighscores);
    stage.addActor(tbChangeLook);
    stage.addActor(tbClanManagement);
    stage.addActor(tbLogout);

    backgroundMusic = Assets.getMusicStream("menu.mp3");
}

From source file:ateamproject.kezuino.com.github.render.screens.RandomGamesScreen.java

public RandomGamesScreen(Game game) {
    super(game);/*from  ww  w  .ja  v  a2s. c o  m*/

    Table table = new Table();

    for (int i = 0; i < 5; i++) {
        Label clan = new Label("OurClan", skin);
        Label clanjoin = new Label("8/10", skin);

        table.add(clan);
        table.add(clanjoin);
        table.row();
    }

    TextButton btnLogin = new TextButton("Press me!", skin);
    btnLogin.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(new GameScreen(game));
        }
    });
    btnLogin.setSize(300, 400);

    table.add(btnLogin).colspan(2);

    table.setPosition(stage.getWidth() / 2, stage.getHeight() / 2);

    //stage.addActor(btnLogin);        
    stage.addActor(table);

    backgroundMusic = Assets.getMusicStream("menu.mp3");

}

From source file:ateamproject.kezuino.com.github.render.screens.SkinSelectScreen.java

public SkinSelectScreen(Game game) {
    super(game);/*from ww w. j  a  v a2  s.  c  om*/
    float x = stage.getWidth() / 2 - 300 / 2;
    float y = stage.getHeight() - 100;

    for (Path path : Assets.getSkins()) {
        TextButton tbChangeLook = new TextButton(path.getFileName().toString(), skin);
        tbChangeLook.addListener(new ClickListener() {
            @Override
            public void clicked(InputEvent event, float x, float y) {
                Gdx.app.getPreferences("user").putString("skin", path.getFileName().toString());
                Assets.setSkin(path.getFileName().toString(), true, () -> game.setScreen(new MainScreen(game)));
            }
        });
        tbChangeLook.setSize(300, 40);

        tbChangeLook.setPosition(x, y);
        stage.addActor(tbChangeLook);
        y = y - 50;
    }

    TextButton tbOptions = new TextButton("Terug", skin);
    tbOptions.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.setScreen(new MainScreen(game));
        }
    });

    tbOptions.setSize(300, 40);
    tbOptions.setPosition(x, y - 50);
    stage.addActor(tbOptions);

    backgroundMusic = Assets.getMusicStream("menu.mp3");
}

From source file:ateamproject.kezuino.com.github.render.screens.StoreScreen.java

public StoreScreen(Game game) {
    super(game);//from   ww w  . j a v a 2s .c o m
    Sound sound = Assets.manager.get("sounds/menu.mp3", Sound.class);
    if (sound != null) {
        sound.loop();
    }

    TextButton btnBack = new TextButton("Terug", skin);
    btnBack.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (sound != null) {
                sound.dispose();
            }
            game.setScreen(new MainScreen(game));

        }
    });
    float x = 240;
    float y = stage.getHeight() / 4;
    btnBack.setSize(200, 40);
    btnBack.setPosition(x, y);

    Label lblStore = new Label("Winkel", skin);
    lblStore.setColor(Color.YELLOW);
    lblStore.setPosition(x, y + 300);

    List listStoreItems = new List(skin);
    String[] skinsArray = { "Skin pack", "Minecraft pack" };
    listStoreItems.setItems((Object) skinsArray);
    listStoreItems.setPosition(x, y + 200);

    TextButton btnBuy = new TextButton("Koop item", skin);
    btnBuy.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            // game.setScreen(new HomeScreen(game));
        }
    });
    btnBuy.setSize(200, 40);
    btnBuy.setPosition(x - 50, y + 50);

    TextButton btnSelect = new TextButton("Selecteer item", skin);
    btnSelect.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            // game.setScreen(new HomeScreen(game));
        }
    });
    btnSelect.setSize(200, 40);
    btnSelect.setPosition(x + 50, y + 50);

    stage.addActor(btnBack);
    stage.addActor(lblStore);
    stage.addActor(listStoreItems);

    backgroundMusic = Assets.getMusicStream("menu.mp3");
}