Example usage for com.badlogic.gdx.utils.viewport ScreenViewport setUnitsPerPixel

List of usage examples for com.badlogic.gdx.utils.viewport ScreenViewport setUnitsPerPixel

Introduction

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

Prototype

public void setUnitsPerPixel(float unitsPerPixel) 

Source Link

Document

Sets the number of pixels for each world unit.

Usage

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);// w  w w  . j  a v  a  2 s. com

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

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  2  s .  c  om

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

From source file:com.o2d.pkayjava.editor.view.SceneControlMediator.java

License:Apache License

public void initScene(String sceneName) {
    ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME);
    ResourceManager resourceManager = facade.retrieveProxy(ResourceManager.NAME);

    ScreenViewport viewport = new ScreenViewport();
    // Yey to whoever made this method
    viewport.setUnitsPerPixel(1f / resourceManager.getProjectVO().pixelToWorld);

    currentSceneVo = sceneLoader.loadScene(sceneName, viewport);
    // TODO: this is now in sceneLoaader but probably will be changed
    // essentials.world = new World(new
    // Vector2(currentSceneVo.physicsPropertiesVO.gravityX,
    // currentSceneVo.physicsPropertiesVO.gravityY), true);
    // essentials.rayHandler.setWorld(essentials.world);

    rootSceneVO = new CompositeItemVO(currentSceneVo.composite);
}

From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouseWithGUI.java

License:Open Source License

/**
 * If you want to run this instance from another
 * {@link ApplicationAdapter} use {@link #create(Stage, Skin, CardHouseDef, InputMultiplexer, Tips)} instead.
 *///from  w  w w. j a v a 2s  .  c o  m
@Override
public void create() {
    if (debug)
        debug("Creating independent application.");

    independentApplication = true;

    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    // ui stuff
    ScreenViewport sv = new ScreenViewport();
    float ui_scale = (float) Math.abs(Math.log(Gdx.graphics.getDensity())) * 2f;
    sv.setUnitsPerPixel(1f / ui_scale);
    Stage stage = new Stage(sv);
    Skin skin = new Skin(Gdx.files.internal("ui/custom/custom.json"));

    // input
    InputMultiplexer inputMultiplexer = new InputMultiplexer();
    Gdx.input.setInputProcessor(inputMultiplexer);
    inputMultiplexer.addProcessor(stage);

    //
    create(stage, skin, new CardHouseDef(), inputMultiplexer, new Tips("CardHouseWithGUI", stage, skin));

    timer.runAfterNRender(new Runnable() {
        @Override
        public void run() {
            startGame(null);
        }
    }, 1);
}

From source file:org.ams.testapps.paintandphysics.cardhouse.CardHouseGameMenu.java

License:Open Source License

@Override
public void create() {
    if (debug)/*w  w w  . j av a  2  s  .  co m*/
        debug("Creating independent application.");

    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    // ui stuff
    ScreenViewport sv = new ScreenViewport();
    float ui_scale = getUIScale();
    sv.setUnitsPerPixel(1f / ui_scale);

    // extended class to set colors of buttons
    this.stage = new Stage(sv) {
        SceneUtil.TraverseTask traverseTask = new SceneUtil.TraverseTask() {

            @Override
            public boolean run(Actor actor) {
                if (actor instanceof TextButton)
                    actor.setColor(cardHouseDef.buttonColor);

                return true; // continue traversing
            }
        };

        @Override
        public void addActor(Actor actor) {
            super.addActor(actor);
            traverseChildren(actor, traverseTask);
        }
    };

    skin = new Skin(Gdx.files.internal("ui/custom/custom.json"));

    // input
    inputMultiplexer = new InputMultiplexer();
    Gdx.input.setInputProcessor(inputMultiplexer);
    inputMultiplexer.addProcessor(stage);

    // background
    background = new Background();
    background.setColor(cardHouseDef.backgroundColor);
    background.setMatchingBackground(cardHouseDef.backgroundTexture);

    tips = new Tips("CardHouseGameMenu", stage, skin);
    preferences = Gdx.app.getPreferences("CardHouseGameMenu");

    showMainMenu();

}

From source file:org.ams.testapps.paintandphysics.physicspuzzle.PhysicsPuzzleGameMenu.java

License:Open Source License

@Override
public void create() {
    timer = new Timer();

    Gdx.app.setLogLevel(Application.LOG_ERROR);

    Gdx.app.log("PhysicsPuzzleGameMenu", "Creating application PhysicsPuzzleGameMenu");

    preferences = Gdx.app.getPreferences("PhysicsPuzzle");

    Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    // ui stuff/*w w  w .ja  va  2  s .c o  m*/
    ScreenViewport sv = new ScreenViewport();
    float ui_scale = (float) Math.abs(Math.log(Gdx.graphics.getDensity())) * 2f;
    sv.setUnitsPerPixel(1f / ui_scale);
    this.stage = new Stage(sv);
    skin = new Skin(Gdx.files.internal("ui/custom/custom.json"));

    // backgrounds and thumbnails are here
    textureAtlas = new TextureAtlas("images/packed/packed.atlas");
    availableRegions = findLinesThatContain("images/packed/packed.atlas", "thumbnails");

    // input
    inputMultiplexer = new InputMultiplexer();
    Gdx.input.setInputProcessor(inputMultiplexer);
    inputMultiplexer.addProcessor(stage);

    // background stuff
    polygonBatch = new PrettyPolygonBatch();
    backgroundCamera = new OrthographicCamera();

    showMainMenu();

}