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

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

Introduction

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

Prototype

public ScalingViewport(Scaling scaling, float worldWidth, float worldHeight, Camera camera) 

Source Link

Usage

From source file:com.sixth.fodder.graphics.Fodder.java

public static Stage getStage() {
    final Stage stage;
    final ScalingViewport view;

    view = new ScalingViewport(Scaling.none, RoadGenerator.getMapWidth() * Cell.getSizeInPix(),
            RoadGenerator.getMapHeight() * Cell.getSizeInPix(), game.camera);

    stage = new Stage(view);
    stage.getBatch().setProjectionMatrix(game.camera.combined);

    return stage;
}

From source file:com.jlabarca.director.Scene.java

License:Apache License

/**
 * Constructor where we supply our own sprite batch.
 * /*from  w ww . j a  v  a2  s.  com*/
 * @param width
 * @param height
 * @param stretch
 * @param batch
 */
public Scene(float width, float height, boolean stretch, Batch batch) {
    super(new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
            new OrthographicCamera()), batch);
    //super();
    inputMultiplexer = new InputMultiplexer(this);

    nodes = new Array<Node>(DEFAULT_LAYER_CAPACITY);
}

From source file:com.gamestudio24.martianrun.stages.GameStage.java

License:Apache License

public GameStage() {
    super(new ScalingViewport(Scaling.stretch, VIEWPORT_WIDTH, VIEWPORT_HEIGHT,
            new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT)));
    setUpCamera();//from w  w  w.  j a va  2 s.  co  m
    setUpStageBase();
    setUpGameLabel();
    setUpMainMenu();
    setUpTouchControlAreas();
    Gdx.input.setInputProcessor(this);
    AudioUtils.getInstance().init();
    onGameOver();
}

From source file:de.hasait.tanks.util.common.Abstract2DScreen.java

License:Apache License

protected Abstract2DScreen(final C pContext, final int pViewportW, final int pViewportH) {
    super();//  w ww.j  a va  2 s .  com

    _context = pContext;

    _viewportW = pViewportW;
    _viewportH = pViewportH;
    _viewportR = new Rectangle(0, 0, _viewportW, _viewportH);

    _camera = new OrthographicCamera();
    _backgroundColor = Color.BLACK;
    _stage = new Stage(new ScalingViewport(Scaling.fit, _viewportW, _viewportH, _camera), _context.getBatch());
    _inputMultiplexer.addProcessor(_stage);
}

From source file:com.forerunnergames.peril.client.ui.screens.AbstractScreen.java

License:Open Source License

public AbstractScreen(final WidgetFactory widgetFactory, final ScreenChanger screenChanger,
        final ScreenSize screenSize, final MouseInput mouseInput, final Batch batch,
        final MBassador<Event> eventBus) {
    Arguments.checkIsNotNull(screenChanger, "screenChanger");
    Arguments.checkIsNotNull(screenSize, "screenSize");
    Arguments.checkIsNotNull(mouseInput, "mouseInput");
    Arguments.checkIsNotNull(batch, "batch");
    Arguments.checkIsNotNull(eventBus, "eventBus");

    this.widgetFactory = widgetFactory;
    this.screenChanger = screenChanger;
    this.screenSize = screenSize;
    this.mouseInput = mouseInput;
    this.eventBus = eventBus;

    normalCursor = widgetFactory.createNormalCursor();

    viewport = new ScalingViewport(GraphicsSettings.VIEWPORT_SCALING, screenSize.referenceWidth(),
            screenSize.referenceHeight(),
            new OrthographicCamera(screenSize.actualWidth(), screenSize.actualHeight()));

    stage = new Stage(viewport, batch);
    stage.addListener(new AddKeyboardFocusListener(stage));
    stage.addCaptureListener(new EscapeKeyListener());

    keyRepeat = new GdxKeyRepeatSystem(Gdx.input, new KeyRepeatListener());
    keyRepeat.setKeyRepeatRate(Input.Keys.LEFT, 50);
    keyRepeat.setKeyRepeatRate(Input.Keys.RIGHT, 50);
    keyRepeat.setKeyRepeatRate(Input.Keys.UP, 50);
    keyRepeat.setKeyRepeatRate(Input.Keys.DOWN, 50);
    keyRepeat.setKeyRepeat(Input.Keys.LEFT, true);
    keyRepeat.setKeyRepeat(Input.Keys.RIGHT, true);
    keyRepeat.setKeyRepeat(Input.Keys.UP, true);
    keyRepeat.setKeyRepeat(Input.Keys.DOWN, true);
    keyRepeat.setKeyRepeat(Input.Keys.BACKSPACE, true);
    keyRepeat.setKeyRepeat(Input.Keys.FORWARD_DEL, true);

    // Should be last line in constructor to avoid any issues leaking 'this' pointer.
    inputProcessor = new InputMultiplexer(new RemoveKeyboardFocusInputProcessor(stage), stage, this);
}

From source file:com.badlogic.gdx.tests.ViewportTest1.java

License:Apache License

static public 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);//from  w  w  w.  j  a va 2 s.c o  m

    viewports.add(new ScalingViewport(Scaling.none, minWorldWidth, minWorldHeight, camera));
    return viewports;
}

From source file:es.eucm.ead.engine.EngineApplicationListener.java

License:Open Source License

/**
 * Creates a Stage as in {@link Stage#Stage()}, but using
 * {@link PolygonSpriteBatch} instead of {@link SpriteBatch}
 * /*from  w w w  . ja va  2s . c  o m*/
 * PolygonSpriteBatch must be used for
 * {@link es.eucm.ead.engine.components.renderers.SpineAnimationComponent}
 * to work properly.
 */
protected Stage createStage() {
    Viewport viewport = new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(),
            new OrthographicCamera());
    PolygonSpriteBatch batch = new PolygonSpriteBatch();
    Stage newStage = new Stage(viewport, batch);
    return newStage;
}

From source file:com.netthreads.libgdx.director.Director.java

License:Apache License

public Viewport getViewPort() {
    return new ScalingViewport(Scaling.stretch, width, height, new OrthographicCamera());
}

From source file:com.jemchicomac.backfire.Backfire.java

License:Apache License

static public Array<Viewport> getViewports(Camera camera) {
    //int minWorldWidth = 640;
    //int minWorldHeight = 480;
    //int maxWorldWidth = 800;
    //int maxWorldHeight = 480;

    int minWorldWidth = VIRTUAL_WIDTH;
    int minWorldHeight = VIRTUAL_HEIGHT;
    int maxWorldWidth = VIRTUAL_WIDTH;
    int maxWorldHeight = VIRTUAL_HEIGHT;

    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);//from  w w  w  . j  a  v  a  2s .c o  m

    viewports.add(new ScalingViewport(Scaling.none, minWorldWidth, minWorldHeight, camera));
    return viewports;
}

From source file:org.catrobat.catroid.stage.StageListener.java

License:Open Source License

private void initScreenMode() {
    switch (project.getScreenMode()) {
    case STRETCH:
        screenshotWidth = ScreenValues.SCREEN_WIDTH;
        screenshotHeight = ScreenValues.SCREEN_HEIGHT;
        screenshotX = 0;/*from   www  .ja v a 2 s.c om*/
        screenshotY = 0;
        viewPort = new ScalingViewport(Scaling.stretch, virtualWidth, virtualHeight, camera);
        break;

    case MAXIMIZE:
        screenshotWidth = maximizeViewPortWidth;
        screenshotHeight = maximizeViewPortHeight;
        screenshotX = maximizeViewPortX;
        screenshotY = maximizeViewPortY;
        viewPort = new ExtendViewport(virtualWidth, virtualHeight, camera);
        break;

    default:
        break;
    }
    viewPort.update(ScreenValues.SCREEN_WIDTH, ScreenValues.SCREEN_HEIGHT, false);
    camera.position.set(0, 0, 0);
    camera.update();
}