Search in sources :

Example 1 with Viewport

use of com.badlogic.gdx.utils.viewport.Viewport in project libgdx by libgdx.

the class ViewportTest1 method create.

public void create() {
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    label = new Label("", skin);
    Table root = new Table(skin);
    root.setFillParent(true);
    root.setBackground(skin.getDrawable("default-pane"));
    root.debug().defaults().space(6);
    root.add(new TextButton("Button 1", skin));
    root.add(new TextButton("Button 2", skin)).row();
    root.add("Press spacebar to change the viewport:").colspan(2).row();
    root.add(label).colspan(2);
    stage.addActor(root);
    viewports = getViewports(stage.getCamera());
    names = getViewportNames();
    stage.setViewport(viewports.first());
    label.setText(names.first());
    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
                label.setText(names.get(index));
                Viewport viewport = viewports.get(index);
                stage.setViewport(viewport);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    }, stage));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputAdapter(com.badlogic.gdx.InputAdapter) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) StretchViewport(com.badlogic.gdx.utils.viewport.StretchViewport) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport) FitViewport(com.badlogic.gdx.utils.viewport.FitViewport) Viewport(com.badlogic.gdx.utils.viewport.Viewport) FillViewport(com.badlogic.gdx.utils.viewport.FillViewport) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 2 with Viewport

use of com.badlogic.gdx.utils.viewport.Viewport in project libgdx by libgdx.

the class ViewportTest1 method getViewports.

public static Array<Viewport> getViewports(Camera camera) {
    int minWorldWidth = 640;
    int minWorldHeight = 480;
    int maxWorldWidth = 800;
    int maxWorldHeight = 480;
    Array<Viewport> viewports = new Array();
    viewports.add(new StretchViewport(minWorldWidth, minWorldHeight, camera));
    viewports.add(new FillViewport(minWorldWidth, minWorldHeight, camera));
    viewports.add(new FitViewport(minWorldWidth, minWorldHeight, camera));
    viewports.add(new ExtendViewport(minWorldWidth, minWorldHeight, camera));
    viewports.add(new ExtendViewport(minWorldWidth, minWorldHeight, maxWorldWidth, maxWorldHeight, camera));
    viewports.add(new ScreenViewport(camera));
    ScreenViewport screenViewport = new ScreenViewport(camera);
    screenViewport.setUnitsPerPixel(0.75f);
    viewports.add(screenViewport);
    viewports.add(new ScalingViewport(Scaling.none, minWorldWidth, minWorldHeight, camera));
    return viewports;
}
Also used : Array(com.badlogic.gdx.utils.Array) FillViewport(com.badlogic.gdx.utils.viewport.FillViewport) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) StretchViewport(com.badlogic.gdx.utils.viewport.StretchViewport) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport) FitViewport(com.badlogic.gdx.utils.viewport.FitViewport) Viewport(com.badlogic.gdx.utils.viewport.Viewport) FillViewport(com.badlogic.gdx.utils.viewport.FillViewport) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) StretchViewport(com.badlogic.gdx.utils.viewport.StretchViewport) FitViewport(com.badlogic.gdx.utils.viewport.FitViewport) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport)

Aggregations

ExtendViewport (com.badlogic.gdx.utils.viewport.ExtendViewport)2 FillViewport (com.badlogic.gdx.utils.viewport.FillViewport)2 FitViewport (com.badlogic.gdx.utils.viewport.FitViewport)2 ScalingViewport (com.badlogic.gdx.utils.viewport.ScalingViewport)2 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)2 StretchViewport (com.badlogic.gdx.utils.viewport.StretchViewport)2 Viewport (com.badlogic.gdx.utils.viewport.Viewport)2 InputAdapter (com.badlogic.gdx.InputAdapter)1 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)1 Array (com.badlogic.gdx.utils.Array)1