Example usage for com.badlogic.gdx.utils.viewport StretchViewport StretchViewport

List of usage examples for com.badlogic.gdx.utils.viewport StretchViewport StretchViewport

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils.viewport StretchViewport StretchViewport.

Prototype

public StretchViewport(float worldWidth, float worldHeight) 

Source Link

Document

Creates a new viewport using a new OrthographicCamera .

Usage

From source file:de.r2soft.empires.client.screens.overlay.PlayerOverlay.java

License:Open Source License

public PlayerOverlay() {
    super(new Stage(new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())));
}

From source file:com.badlogicgames.superjumper.mainmenu.MainMenuScreen.java

License:Apache License

public MainMenuScreen(SuperJumper game) {
    this.game = game;
    stage = new Stage(new StretchViewport(SuperJumper.screenWidth, SuperJumper.screenHeight), game.batch);
    stage.addActor(new BackGroundActor());
    stage.addActor(new LogoActor());
    stage.addActor(new StartButtonActor(game));
    stage.addActor(new SoundButtonActor());
}

From source file:net.mwplay.cocostudio.ui.DemoScreen.java

License:Apache License

@Override
public void show() {
    super.show();
    stage = new Stage(new StretchViewport(DemoGame.GAME_WIDTH, DemoGame.GAME_HEIGHT));
    InputMultiplexer multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(stage);//w w  w  . j  a v a2 s.co m
    initDemoChange(multiplexer);
    Gdx.input.setInputProcessor(multiplexer);
    findAllDemos();
    defaultFont = Gdx.files.internal("share/MLFZS.TTF");
    changeDemo();
}

From source file:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createLevelAndHealthLayer() {
    Stage stage = new Stage(new StretchViewport(486, 864));
    Skin skin = new Skin();
    Table table = new Table();
    table.top().pad(10);/*from   w  w  w  . j a v  a2  s. c  om*/

    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(
            Gdx.files.internal("ui/fonts/Century Gothic Bold.ttf"));
    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = 40;
    parameter.borderColor = Color.BLACK;
    parameter.borderWidth = 3;
    BitmapFont font = generator.generateFont(parameter);
    generator.dispose();
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);

    skin.add("star", new Texture("ui/icons/star.png"));
    skin.add("shield", new Texture("ui/icons/shield.png"));
    skin.add("brick", new Texture("ui/icons/brick.png"));
    skin.add("swipe128", new Texture("ui/icons/swipe128.png"));

    float padding = 10;
    Image icon = new Image(skin.getDrawable("star"));
    if (Global.debugLevelUp) {
        icon.addListener(new ClickListener() {
            @Override
            public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
                if (Engine.systemManager.has(LevelProgressionSystem.class)) {
                    for (Entity entity : Engine.systemManager.get(LevelProgressionSystem.class).entities) {
                        Engine.garbageManager.markForDeletion(entity);
                    }
                }
                super.touchUp(event, x, y, pointer, button);
            }
        });
    }
    table.add(icon).pad(padding);
    Label levelLabel = new Label("", labelStyle);
    table.add(levelLabel).pad(padding);
    icon = new Image(skin.getDrawable("shield"));
    table.add(icon).pad(padding);
    Label healthLabel = new Label("", labelStyle);
    table.add(healthLabel).pad(padding);
    icon = new Image(skin.getDrawable("brick"));
    table.add(icon).pad(padding);
    Label brickLabel = new Label("", labelStyle);
    table.add(brickLabel).pad(padding);

    table.row();

    // swipe
    if (Engine.systemManager.has(LevelProgressionSystem.class)) {
        if (Engine.systemManager.get(LevelProgressionSystem.class).level < 5) {
            icon = new Image(skin.getDrawable("swipe128"));
            table.add(icon).padTop(350).colspan(6);
            Global.swipeIcon = icon;

        }
    }

    //        table.setDebug(true);
    table.setFillParent(true);
    stage.addActor(table);

    Global.LEVEL_LABEL = levelLabel;
    Global.HEALTH_LABEL = healthLabel;
    Global.BRICK_LABEL = brickLabel;

    if (Engine.systemManager.has(LevelProgressionSystem.class)) {
        Global.LEVEL_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).level);
        Global.HEALTH_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).health);
        Global.BRICK_LABEL.setText("" + Engine.systemManager.get(LevelProgressionSystem.class).nrOfBricks);
    }

    Engine.inputManager.add(stage);
    return new Layer("topLayer", stage, table);
}

From source file:gui.screen.StartScreen.java

public StartScreen(Game game, Client client, Server server) {
    super(game, client, server);

    //General Object initalisation
    this.stage = new Stage(new StretchViewport(Constants.SCREENWIDTH, Constants.SCREENHEIGHT));
    inputHandler.setInputSource(stage);/*w  w w.ja v a 2  s.  c  om*/

    //Initialise Font
    FreeTypeFontGenerator.FreeTypeFontParameter fontOptions = new FreeTypeFontGenerator.FreeTypeFontParameter();
    fontOptions.size = 11;

    /*------------------------AUDIO------------------------**/

    AudioManager.setCurrentMusic(AudioManager.getStartScreenMusic());
    AudioManager.getCurrentMusic().setLooping(true);
    AudioManager.getCurrentMusic().play();
    AudioManager.getCurrentMusic().setVolume(AudioManager.getMusicVolume());

    /*------------------------LABEL STYLE------------------------**/
    Label.LabelStyle labelStyle = new Label.LabelStyle();
    fontOptions.size = 70;
    labelStyle.font = TextureManager.menuFont.generateFont(fontOptions);
    labelStyle.fontColor = Color.GOLD;

    rootTable = new Table();
    rootTable.setFillParent(true);
    stage.addActor(rootTable);

    gameTitel = new Label("I like trains", labelStyle);
    gameTitel.setText(Constants.WINDOWTITEL);
    gameTitel.setAlignment(Align.center);
    gameTitel.setPosition((Constants.SCREENWIDTH - gameTitel.getWidth()) / 2,
            Constants.SCREENHEIGHT - gameTitel.getHeight() - 10);
    stage.addActor(gameTitel);

    /*------------------------LABEL STYLE------------------------**/
    Label.LabelStyle labelStyle2 = new Label.LabelStyle();
    fontOptions.size = 30;
    labelStyle2.font = TextureManager.menuFont.generateFont(fontOptions);
    labelStyle2.fontColor = Color.GOLDENROD;

    pressAnyKey = new Label("Press any key...", labelStyle2);
    pressAnyKey.setAlignment(Align.center);
    pressAnyKey.setPosition((Constants.SCREENWIDTH - pressAnyKey.getWidth()) / 2,
            Constants.SCREENHEIGHT - gameTitel.getHeight() - pressAnyKey.getHeight() - 40);
    stage.addActor(pressAnyKey);

    if (Constants.ISRUNNINGONSMARTPHONE) {
        pressAnyKey.setText("Tap anywhere...");
    }

    //Set background image
    rootTable.background(new TextureRegionDrawable(new TextureRegion(TextureManager.startBackground)));

}

From source file:de.r2soft.empires.client.screens.overlay.MainMenuOverlay.java

License:Open Source License

public MainMenuOverlay() {
    super(new Stage(new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())));
}

From source file:com.tumblr.oddlydrawn.nahlc.screens.MainMenuScreen.java

License:Apache License

public MainMenuScreen(Game g) {
    game = g;/*from w w  w .j  av  a2s.c  om*/
    assets = new Assets();
    assets.initMainMenu();
    stage = new Stage(new StretchViewport(Renderer.WIDTH, Renderer.HEIGHT));
    Gdx.input.setInputProcessor(stage);
    skin = new Skin();

    skin.add("default", new BitmapFont(Gdx.files.internal("data/fonts/deja.fnt")));

    skin.add("patch", new NinePatch(assets.getBoxPatch()));

    Image boxPatchImage = new Image(assets.getBoxPatch());
    boxPatchImage.setSize(Renderer.WIDTH - 40, Renderer.HEIGHT - 40);
    boxPatchImage.setPosition(20, 22);
    stage.addActor(boxPatchImage);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.font = skin.getFont("default");
    textButtonStyle.up = new NinePatchDrawable(assets.getBoxPatch());
    skin.add("default", textButtonStyle);

    table = new Table();
    table.setFillParent(true);
    table.setPosition(0, 0);
    stage.addActor(table);
    table.debug();
    table.debugTable();

    Image titleImage = new Image(assets.getTitleSprite());
    table.add(titleImage).padBottom(200f);
    table.row();

    TextButton newGameButton = new TextButton("New Game", skin);
    table.add(newGameButton).padBottom(20f);
    table.row();

    TextButton licenseButton = new TextButton("License", skin);
    table.add(licenseButton).padBottom(10f);
    table.row();

    newGameButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            dispose();
            game.setScreen(new SetupScreen(game));
        }
    });

    licenseButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent event, Actor actor) {
            dispose();
            game.setScreen(new LicenseScreen(game));
        }
    });
}

From source file:io.github.deathsbreedgames.spacerun.screens.LoadingScreen.java

public LoadingScreen(AssetManager manager) {
    super("Loading", manager);
    // Tell the manager to load assets for the loading screen
    manager.load("gfx/loading/loading.pack", TextureAtlas.class);
    // Wait until they are finished loading
    manager.finishLoading();//from www. j  a  v a2s.co  m

    // Setup the camera
    camera = new OrthographicCamera(GlobalVars.width, GlobalVars.height);
    camera.position.set(GlobalVars.width / 2, GlobalVars.height / 2, 0);
    camera.update();

    // Initialize the stage where we will place everything
    stage = new Stage(new StretchViewport(GlobalVars.width, GlobalVars.height));

    // Get our textureatlas from the manager
    TextureAtlas atlas = manager.get("gfx/loading/loading.pack", TextureAtlas.class);

    // Grab the regions from the atlas and create some images
    logo = new Image(atlas.findRegion("loading-text"));
    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"));

    // Or if you only need a static bar, you can do
    loadingBar = new Image(atlas.findRegion("loading-bar1"));

    // Add all the actors to the stage
    stage.addActor(screenBg);
    stage.addActor(loadingBar);
    stage.addActor(loadingBg);
    stage.addActor(loadingBarHidden);
    stage.addActor(loadingFrame);
    stage.addActor(logo);

    // Make the background fill the screen
    screenBg.setSize(GlobalVars.width, GlobalVars.height);

    // Place the "logo" in the middle of the screen and 100px up
    logo.setScale(0.5f);
    logo.setX((GlobalVars.width - logo.getWidth() * logo.getScaleX()) / 2);
    logo.setY((GlobalVars.height - logo.getHeight()) / 2 + 100);

    // Place the loading frame in the middle of the screen
    loadingFrame.setX((GlobalVars.width - loadingFrame.getWidth()) / 2);
    loadingFrame.setY((GlobalVars.height - loadingFrame.getHeight()) / 2);

    // Place the loading bar at the same spot as the frame (with a few adjustments)
    loadingBar.setX(loadingFrame.getX() + 15);
    loadingBar.setY(loadingFrame.getY() + 5);

    // Place the image that will hide the bar on top of the bar (with a few adjustments)
    loadingBarHidden.setX(loadingBar.getX() + 35);
    loadingBarHidden.setY(loadingBar.getY() - 3);

    // The start position of how far to move the hidden loading bar
    startX = loadingBarHidden.getX();
    endX = 440;

    // The rest of the hiddent bar
    loadingBg.setSize(450, 50);
    loadingBg.setX(loadingBarHidden.getX() + 30);
    loadingBg.setY(loadingBarHidden.getY() + 3);

    // Add everything to be loaded, for instance:
    manager.load("gfx/deathsbreedgames/logo.png", Texture.class);
    manager.load("gfx/space-run.png", Texture.class);
    manager.load("gfx/ui/buttons.pack", TextureAtlas.class);
    manager.load("gfx/sprites/pickups.pack", TextureAtlas.class);
    manager.load("gfx/sprites/spaceships.pack", TextureAtlas.class);
    manager.load("gfx/sprites/bullets.pack", TextureAtlas.class);
}

From source file:io.github.deathsbreedgames.spacerun.screens.MainMenuScreen.java

public MainMenuScreen(AssetManager manager) {
    super("Splash", manager);

    // Setup logo
    camera = new OrthographicCamera(GlobalVars.width, GlobalVars.height);
    camera.position.set(GlobalVars.width / 2, GlobalVars.height / 2, 0f);
    camera.update();/*from   w w w .ja v  a  2s  . c o m*/
    batch = new SpriteBatch();
    logo = manager.get("gfx/space-run.png", Texture.class);

    // Setup TextButtonStyle
    mainStage = new Stage(new StretchViewport(GlobalVars.width, GlobalVars.height));
    buttonAtlas = manager.get("gfx/ui/buttons.pack", TextureAtlas.class);
    buttonSkin = new Skin(buttonAtlas);
    Gdx.input.setInputProcessor(mainStage);

    buttonFont = new BitmapFont();
    buttonFont.scale(0.5f);

    TextButtonStyle buttonStyle = new TextButtonStyle();
    buttonStyle.up = buttonSkin.getDrawable("MainMenu-normal");
    buttonStyle.down = buttonSkin.getDrawable("MainMenu-down");
    buttonStyle.over = buttonSkin.getDrawable("MainMenu-hover");
    buttonStyle.font = buttonFont;

    // Create the TextButtons
    TextButton playButton = new TextButton(GlobalVars.gameBundle.get("play"), buttonStyle);
    playButton.setPosition(GlobalVars.width / 2 - playButton.getWidth() / 2, 250f);
    mainStage.addActor(playButton);
    playButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent e, Actor a) {
            // Change to the Game
            setNextScreen("ShipSelect");
            setDone(true);
        }
    });

    TextButton helpButton = new TextButton(GlobalVars.gameBundle.get("help"), buttonStyle);
    helpButton.setPosition(GlobalVars.width / 2 - helpButton.getWidth() / 2, 210f);
    mainStage.addActor(helpButton);
    helpButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent e, Actor a) {
            setNextScreen("Help");
            setDone(true);
        }
    });

    TextButton optionsButton = new TextButton(GlobalVars.gameBundle.get("options"), buttonStyle);
    optionsButton.setPosition(GlobalVars.width / 2 - optionsButton.getWidth() / 2, 170f);
    mainStage.addActor(optionsButton);
    optionsButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent e, Actor a) {
            setNextScreen("Options");
            setDone(true);
        }
    });

    TextButton creditsButton = new TextButton(GlobalVars.gameBundle.get("credits"), buttonStyle);
    creditsButton.setPosition(GlobalVars.width / 2 - creditsButton.getWidth() / 2, 130f);
    mainStage.addActor(creditsButton);
    creditsButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent e, Actor a) {
            // Change to the Credits Menu
            setNextScreen("CreditsMenu");
            setDone(true);
        }
    });

    TextButton quitButton = new TextButton(GlobalVars.gameBundle.get("exit"), buttonStyle);
    quitButton.setPosition(GlobalVars.width / 2 - quitButton.getWidth() / 2, 90f);
    mainStage.addActor(quitButton);
    quitButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent e, Actor a) {
            // Quit
            Gdx.app.exit();
        }
    });
}

From source file:io.github.deathsbreedgames.spacerun.screens.HelpScreen.java

public HelpScreen(AssetManager manager) {
    super("MainMenu", manager);

    // Help stuff
    camera = new OrthographicCamera(GlobalVars.width, GlobalVars.height);
    camera.position.set(GlobalVars.width / 2, GlobalVars.height / 2, 0);
    camera.update();/*  w w  w  . ja v  a 2s .co  m*/
    batch = new SpriteBatch();
    titleFont = new BitmapFont();
    titleFont.scale(0.75f);
    textFont = new BitmapFont();
    textFont.scale(0.1f);
    pickupAtlas = manager.get("gfx/sprites/pickups.pack", TextureAtlas.class);

    // Button stuff
    mainStage = new Stage(new StretchViewport(GlobalVars.width, GlobalVars.height));
    buttonAtlas = manager.get("gfx/ui/buttons.pack", TextureAtlas.class);
    buttonSkin = new Skin(buttonAtlas);
    Gdx.input.setInputProcessor(mainStage);

    buttonFont = new BitmapFont();
    buttonFont.scale(0.3f);

    TextButtonStyle buttonStyle = new TextButtonStyle();
    buttonStyle.up = buttonSkin.getDrawable("MainMenu-normal");
    buttonStyle.down = buttonSkin.getDrawable("MainMenu-down");
    buttonStyle.over = buttonSkin.getDrawable("MainMenu-hover");
    buttonStyle.font = buttonFont;

    TextButton backButton = new TextButton(GlobalVars.gameBundle.get("back"), buttonStyle);
    backButton.setPosition(GlobalVars.width / 2 - backButton.getWidth() / 2, 10f);
    mainStage.addActor(backButton);
    backButton.addListener(new ChangeListener() {
        public void changed(ChangeEvent e, Actor a) {
            setNextScreen("MainMenu");
            setDone(true);
        }
    });
}