Example usage for com.badlogic.gdx.scenes.scene2d Stage Stage

List of usage examples for com.badlogic.gdx.scenes.scene2d Stage Stage

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d Stage Stage.

Prototype

public Stage(Viewport viewport) 

Source Link

Document

Creates a stage with the specified viewport.

Usage

From source file:at.hid.tabletopsimulator.screens.About.java

License:Apache License

@Override
public void show() {
    TableTopSimulator.debug(this.getClass().toString(), "creating About screen");
    stage = new Stage(new ExtendViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));

    Gdx.input.setInputProcessor(stage);//from w w  w  .j  a  va  2 s.  c  o  m

    // creating skin
    TableTopSimulator.debug(this.getClass().toString(), "creating skin");
    skin = TableTopSimulator.assets.get("ui/gui.json", Skin.class);

    table = new Table(skin);
    //      table.setFillParent(true);
    //      table.setBounds(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    // creating heading
    TableTopSimulator.debug(this.getClass().toString(), "creating heading");
    Label lblHeading = new Label(TableTopSimulator.getLangBundle().format("About.lblHeading.text"), skin);

    final Label lblContent = new Label("http://libgdx.badlogicgames.com/\r\n" + "\r\n"
            + "libGDX is licensed under the Apache 2 License,\r\n"
            + "meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.\r\n"
            + "We love to get (non-mandatory) credit in case you release a game or app using libgdx!", skin,
            "content");

    // creating list

    final List<String> listAbout = new List<String>(skin, "content");
    ArrayList<String> newItems = new ArrayList<String>();
    newItems.add("libgdx");
    newItems.add("libgdx-utils");
    newItems.add("flare gameart");
    String[] data = new String[newItems.size()];
    listAbout.setItems(newItems.toArray(data));
    listAbout.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            if (listAbout.getSelected().equals("libgdx")) {
                lblContent.clear();
                lblContent.setText("http://libgdx.badlogicgames.com/\r\n" + "\r\n"
                        + "libGDX is licensed under the Apache 2 License,\r\n"
                        + "meaning you can use it free of charge, without strings attached in commercial and non-commercial projects.\r\n"
                        + "We love to get (non-mandatory) credit in case you release a game or app using libgdx!");
            } else if (listAbout.getSelected().equals("libgdx-utils")) {
                lblContent.clear();
                lblContent.setText("https://bitbucket.org/dermetfan/libgdx-utils/wiki/Home\r\n" + "\r\n"
                        + "/* Copyright (c) 2014 PixelScientists\r\n" + "*\r\n" + "* The MIT License (MIT)\r\n"
                        + "*\r\n"
                        + "* Permission is hereby granted, free of charge, to any person obtaining a copy of\r\n"
                        + "* this software and associated documentation files (the \"Software\"), to deal in\r\n"
                        + "* the Software without restriction, including without limitation the rights to\r\n"
                        + "* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\n"
                        + "* the Software, and to permit persons to whom the Software is furnished to do so,\r\n"
                        + "* subject to the following conditions:\r\n" + "*\r\n"
                        + "* The above copyright notice and this permission notice shall be included in all\r\n"
                        + "* copies or substantial portions of the Software.\r\n" + "*\r\n"
                        + "* THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n"
                        + "* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\n"
                        + "* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\n"
                        + "* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\n"
                        + "* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\n"
                        + "* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n"
                        + "*/");
            } else if (listAbout.getSelected().equals("flare gameart")) {
                lblContent.clear();
                lblContent.setText("https://github.com/clintbellanger/flare-game\r\n" + "\r\n"
                        + "Flare (the game) is Copyright 2010-2013 Clint Bellanger. Contributors retain copyrights to their original contributions.\r\n"
                        + "\r\n" + "The Flare Engine is released under GPL version 3 or later.\r\n" + "\r\n"
                        + "All of Flare's art and data files are released under CC-BY-SA 3.0. Later versions are permitted.\r\n"
                        + "\r\n"
                        + "The Liberation Sans fonts version 2 are released under the SIL Open Font License, Version 1.1.\r\n"
                        + "\r\n"
                        + "The GNU Unifont font is released under GPL v2, with the exception that embedding the font in a document does not in itself bind that document to the terms of the GPL.");
            }
        }
    });

    // creating buttons
    TableTopSimulator.debug(this.getClass().toString(), "creating buttons");
    TextButton btnBack = new TextButton(TableTopSimulator.getLangBundle().format("About.btnBack.text"), skin);
    btnBack.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            TableTopSimulator.debug(this.getClass().toString(), "switching to Options screen");
            ((Game) Gdx.app.getApplicationListener()).setScreen(new Options());
            dispose();
        }
    });
    btnBack.pad(10);

    ScrollPane spAboutList = new ScrollPane(null, skin);
    ScrollPane spAboutContent = new ScrollPane(null, skin);

    SplitPane splitAbout = new SplitPane(spAboutList, spAboutContent, false, skin);
    splitAbout.setSplitAmount(0.2f);

    spAboutList.setWidget(listAbout);
    spAboutContent.setWidget(lblContent);

    // building ui
    TableTopSimulator.debug(this.getClass().toString(), "building ui");
    table.add(lblHeading).spaceBottom(100).row();
    table.add(splitAbout).spaceBottom(15).width(1200).row();
    table.add(btnBack).spaceBottom(15).row();
    if (TableTopSimulator.DEBUG) {
        table.debug(); // draw debug lines 
        splitAbout.debug(); // draw debug lines 
    }
    stage.addActor(table);
}

From source file:com.agateau.ui.StageScreen.java

License:Apache License

public StageScreen(Viewport viewport) {
    mViewport = viewport;
    mStage = new Stage(mViewport);
}

From source file:com.alterego.jelly.screens.PlayGameScreen.java

License:Apache License

@Override
public void show() {
    Camera cam = new OrthographicCamera(Const.GAME_WIDTH, Const.GAME_HEIGHT);
    StretchViewport view = new StretchViewport(Const.GAME_WIDTH, Const.GAME_HEIGHT, cam);
    stage = new Stage(view);
    batch = (SpriteBatch) stage.getBatch();

    Gdx.input.setInputProcessor(stage);/*w ww  .  ja v  a 2  s.  c  o m*/

    winnerUi = new WinnerUI(game);
    pauseUi = new PauseUI(game);
    marketUi = new MarketFreezeUI(this);

    levelBuilder = new LevelBuilder(gameLevel);

    rebuildStage();
    init();
}

From source file:com.amerticum.chosenchess.view.MainMenu.java

License:Apache License

private void initUI() {
    stage = new Stage(new ScreenViewport());
    Gdx.input.setInputProcessor(stage);/*from  w  w  w  .j  a  v  a 2 s .c o  m*/
    netPlayButton = new TextButton(" Play with a friend ", Assets.skin, "menu");
    computerPlayButton = new TextButton(" Play computer ", Assets.skin, "menu");

    netPlayButton.setPosition(Gdx.graphics.getWidth() / 2 - netPlayButton.getWidth() / 2,
            Gdx.graphics.getHeight() - netPlayButton.getHeight() - Constants.MARGE);
    computerPlayButton.setPosition(Gdx.graphics.getWidth() / 2 - netPlayButton.getWidth() / 2,
            netPlayButton.getY() - netPlayButton.getHeight() - Constants.MARGE);

    computerPlayButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
            ChoSenGame.game.setScreen(new GameScreen(echiquier));
        }
    });

    netPlayButton.addListener(new ClickListener() {
        @Override
        public void clicked(InputEvent event, float x, float y) {
        }
    });

    stage.addActor(netPlayButton);
    stage.addActor(computerPlayButton);
}

From source file:com.arkanoid.Screens.LoadingScreen.java

License:Open Source License

public LoadingScreen(ArkanoidGame game) {
    super(game);// w  ww .  j a va  2s  .  c  o m

    // The games's constants, some not so constant ;-)
    CuasiConstantes.inicializar();

    // Screen's configuration
    camera = new OrthographicCamera();
    //        viewport = new StretchViewport(640, 800, camera);
    viewport = new FitViewport(SCREEN_WIDTH, SCREEN_HEIGHT, camera);

    stage = new Stage(viewport);

    // Loading text
    skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
    loading = new Label("Loading...", skin);
    loading.setPosition(320 - loading.getWidth() / 2, 180 - loading.getHeight() / 2);
    stage.addActor(loading);
}

From source file:com.badlogic.gdx.ai.tests.BehaviorTreeViewer.java

License:Apache License

@Override
public void create() {
    step = 0;//w  w  w. ja va  2 s.c o  m
    taskNodes = new ObjectMap<Task<Dog>, TaskNode>();
    BehaviorTreeParser<Dog> parser = new BehaviorTreeParser<Dog>(BehaviorTreeParser.DEBUG_NONE);
    BehaviorTree<Dog> tree = parser.parse(Gdx.files.internal("data/dog.tree"), null);
    dog = new Dog("Dog 1", tree);
    tree.addListener(new BehaviorTree.Listener<Dog>() {
        @Override
        public void statusUpdated(Task<Dog> task, Task.Status previousStatus) {
            TaskNode tn = taskNodes.get(task);
            tn.updateStatus(previousStatus, step);
        }

        @Override
        public void childAdded(Task<Dog> task, int index) {
            TaskNode parentNode = taskNodes.get(task);
            Task<Dog> child = task.getChild(index);
            addToTree(displayTree, parentNode, child, null, 0);
            displayTree.expandAll();
        }
    });
    KryoUtils.initKryo();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));

    treeStatus = SUSPENDED;

    runDelaySlider = new Slider(0, 5, 0.01f, false, skin);
    runDelaySlider.setValue(.5f);

    runButton = new TextButton("Run", skin);

    stepButton = new TextButton("Step", skin);

    loadButton = new TextButton("Load", skin);
    loadButton.setDisabled(true);

    saveButton = new TextButton("Save", skin);

    stepLabel = new Label(new StringBuilder(LABEL_STEP + step), skin);

    stage = new Stage(new ScreenViewport());

    Table table = new Table();
    table.row().height(20).fillX();
    table.add(runDelaySlider);
    table.add(runButton);
    table.add(stepButton);
    table.add(saveButton);
    table.add(loadButton);
    table.add(stepLabel);
    table.row();
    displayTree = new Tree(skin);

    redrawTree();

    table.add(displayTree).colspan(3).fillX().fillY().expand(true, true);

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

    saveButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            save();
            saved = true;
            loadButton.setDisabled(false);
        }
    });

    loadButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            load();
        }
    });

    stepButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            treeStatus = STEP; // step();
        }
    });

    runButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (treeStatus == SUSPENDED) {
                treeStatus = RUNNING;
                delay = runDelaySlider.getValue(); // this makes it start immediately
                runButton.setText("Suspend");
                stepButton.setDisabled(true);
                saveButton.setDisabled(true);
                loadButton.setDisabled(true);
            } else {
                treeStatus = SUSPENDED;
                runButton.setText("Run");
                stepButton.setDisabled(false);
                saveButton.setDisabled(false);
                loadButton.setDisabled(!saved);
            }
        }
    });

    Gdx.input.setInputProcessor(stage);

    setScreen(this);
}

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 o m*/

    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:com.blackboxgaming.engine.factories.LayerFactory.java

public static Layer createFireLayer() {
    Stage stage = new Stage(new StretchViewport(640, 480));
    Table table = new Table();
    BitmapFont font = new BitmapFont();
    Button button;//from   ww w .ja  v a  2s.  c o m

    Skin skin = new Skin();
    skin.add("bluebox", new Texture("textures/bluebox.jpg"));
    skin.add("greenbox", new Texture("textures/greenbox.jpg"));
    skin.add("redbox", new Texture("textures/redbox.jpg"));

    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("redbox"),
            skin.getDrawable("greenbox"), skin.getDrawable("bluebox"), font);

    button = new ImageTextButton("Fire", style);
    button.setHeight(50);
    button.setWidth(50);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new InputListener() {

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            Gdx.input.getInputProcessor().keyDown(Keys.SPACE);
            return true;
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            Gdx.input.getInputProcessor().keyUp(Keys.SPACE);
        }

    });
    table.add(button).pad(50).center();

    table.pack();
    table.setPosition(640 - table.getWidth(), 0);
    stage.addActor(table);

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

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

public static Layer createJoystickLayer() {
    Stage stage = new Stage(new StretchViewport(1280, 720));
    Table table = new Table();
    MyListener listener = new MyListener();
    BitmapFont font = new BitmapFont();
    Button button;// w ww  . j a  va  2  s.c o m

    Skin skin = new Skin();
    skin.add("cirlce", new Texture("textures/circle.png"));
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("cirlce"),
            skin.getDrawable("cirlce"), skin.getDrawable("cirlce"), font);

    button = new ImageTextButton("Move", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new MoveListener());
    table.add(button).pad(50).expandX().left();

    button = new ImageTextButton("Fire", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(listener);
    table.add(button).pad(50).bottom().right();

    table.setDebug(true);
    table.setFillParent(true);
    table.bottom().left();
    stage.addActor(table);

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

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

public static Layer createJoystickControlLayer() {
    Stage stage = new Stage(new StretchViewport(1280, 720));
    Table table = new Table();
    BitmapFont font = new BitmapFont();
    Button button;//from  www . j  a va2s.c  o  m

    Skin skin = new Skin();
    skin.add("cirlce", new Texture("textures/circle.png"));
    ImageTextButtonStyle style = new ImageTextButtonStyle(skin.getDrawable("cirlce"),
            skin.getDrawable("cirlce"), skin.getDrawable("cirlce"), font);

    button = new ImageTextButton("Debug Options", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            Engine.game.setScreen(Engine.screens.get("debug"));
            return false;
        }
    });
    table.add(button).pad(50).padLeft(100).expandX().left();
    table.row();

    button = new ImageTextButton("L Boost", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(true, false, true));
    table.add(button).pad(50).padLeft(100).expandX().left();

    button = new ImageTextButton("R Boost", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(false, true, true));
    table.add(button).pad(50).padRight(100).bottom().right();
    table.row();

    button = new ImageTextButton("Left", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(true, false, false));
    table.add(button).pad(50).padLeft(100).expandX().left();

    button = new ImageTextButton("Right", style);
    button.setHeight(150);
    button.setWidth(150);
    button.setName(((ImageTextButton) button).getText().toString());
    button.addListener(new Rotate(false, true, false));
    table.add(button).pad(50).padRight(100).bottom().right();

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

    if (Engine.systemManager.has(OrbitCameraSystem.class)
            && Engine.systemManager.get(OrbitCameraSystem.class).mouseListener) {
        InputProcessor tmp = Engine.systemManager.get(OrbitCameraSystem.class).orbitCameraController;
        Engine.inputManager.remove(tmp);
        Engine.inputManager.add(stage);
        Engine.inputManager.add(tmp);
    } else {
        Engine.inputManager.add(stage);
    }

    return new Layer("controlLayer", stage);
}