Java 类com.badlogic.gdx.utils.viewport.ScalingViewport 实例源码

项目:libgdxcn    文件:ViewportTest1.java   
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);

    viewports.add(new ScalingViewport(Scaling.none, minWorldWidth, minWorldHeight, camera));
    return viewports;
}
项目:gdxjam-ugg    文件:GDXJam.java   
@Override
public void create() {
    //Init statics
    OBJECT_ID = 0;
    LoaderUtils loaderUtils = new LoaderUtils();
    loaderUtils.init();

       //Init cameras and controllers
    ScreenViewport viewportGUI = new ScreenViewport(new OrthographicCamera());
    CameraController oCameraGUI = new CameraController(viewportGUI);
    oCameraGUI.getViewport().apply(true);
    ScalingViewport viewportPlay = new ScalingViewport(Scaling.fillY, TARGET_WIDTH, TARGET_HEIGHT);
    CameraController oCameraPlay = new CameraController(viewportPlay);
    oCameraPlay.setBoundaries(worldBoundaries);

    SpriteBatch batch = new SpriteBatch();
    Stage playStage = new Stage(viewportPlay, batch);
    Stage guiStage = new Stage(viewportGUI, batch);

    InputController oInputCtrl = new InputController(playStage, guiStage);
    PhysicsController physicsCtrl = new PhysicsController(oCameraPlay, TIME_STEP, 1, 1);
    EngineController oEngineCtrl = new EngineController(playStage, guiStage, physicsCtrl, oInputCtrl, oCameraPlay, loaderUtils);
    GUIController oGuiController = new GUIController(oCameraGUI, oCameraPlay, oInputCtrl, guiStage, loaderUtils);
    MapController oMapController = new MapController(oEngineCtrl, oCameraPlay);
    oMapController.loadMap("data/gameMap.tmx", batch, true);

       //Set camera listener, for camera control
    Scene2dListenersUtils.setupPlayStageCameraListener(playStage, oCameraPlay, oInputCtrl);

       //Set screen
       mainScreen = new MainScreen(oEngineCtrl, oInputCtrl, oCameraGUI, oCameraPlay, oGuiController);
    this.setScreen(mainScreen);
}
项目:cachebox3.0    文件:CacheboxMain.java   
@Override
public void create() {

    Gdx.graphics.setContinuousRendering(false);

    final Viewport viewport = new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), new OrthographicCamera());
    final Batch batch = new SpriteBatch();

    final Splash splash = new Splash(new Splash.LoadReady() {
        @Override
        public void ready() {
            Config.AppRaterlaunchCount.setValue(Config.AppRaterlaunchCount.getValue() + 1);
            Config.AcceptChanges();

            // Splash is ready with initialisation
            // now switch Stage to ViewManager
            Gdx.app.postRunnable(new Runnable() {
                @Override
                public void run() {
                    StageManager.setMainStage(new ViewManager(
                            CacheboxMain.this, StageManager.viewport, StageManager.batch));
                    batch.dispose();
                }
            });
        }
    }, viewport, batch);

    StageManager.setMainStage(splash);

    Gdx.graphics.requestRendering();
    CB.initThreadCheck();
}
项目:LibGDX-MVC-Tutorial    文件:StageComponent.java   
public static Stage createStage(float vp_width, float vp_height)
{
    Stage stage = new Stage(new ScalingViewport(Scaling.fill, vp_width, vp_height));
    stage.getViewport().setCamera(new OrthographicCamera(vp_width, vp_height));
    ((OrthographicCamera) stage.getCamera()).position.set(((OrthographicCamera) stage.getCamera()).viewportWidth / 2, ((OrthographicCamera) stage.getCamera()).viewportHeight / 2, 0f);
    ((OrthographicCamera) stage.getCamera()).zoom = 1f;
    ((OrthographicCamera) stage.getCamera()).update();
    return stage;
}
项目:GDXJam    文件:CameraSystem.java   
public CameraSystem(float viewportWidth, float viewportHeight) {
    camera = new OrthographicCamera(viewportWidth, viewportHeight);
    viewport = new ScalingViewport(Scaling.stretch, viewportWidth,
            viewportHeight, camera);

    addParalaxLayer(0, 0.0f);
    addParalaxLayer(1, 0.10f);
    addParalaxLayer(2, 0.50f);
}
项目:libgdxcn    文件:StagePerformanceTest.java   
@Override
public void create () {
    batch = new SpriteBatch();
    font = new BitmapFont();
    stage = new Stage(new ScalingViewport(Scaling.fit, 24, 12));
    regions = new TextureRegion[8 * 8];
    sprites = new Sprite[24 * 12];

    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    for (int y = 0; y < 8; y++) {
        for (int x = 0; x < 8; x++) {
            regions[x + y * 8] = new TextureRegion(texture, x * 32, y * 32, 32, 32);
        }
    }

    Random rand = new Random();
    for (int y = 0, i = 0; y < 12; y++) {
        for (int x = 0; x < 24; x++) {
            Image img = new Image(regions[rand.nextInt(8 * 8)]);
            img.setBounds(x, y, 1, 1);
            stage.addActor(img);
            sprites[i] = new Sprite(regions[rand.nextInt(8 * 8)]);
            sprites[i].setPosition(x, y);
            sprites[i].setSize(1, 1);
            i++;
        }
    }
}
项目:libgdxcn    文件:ViewportTest2.java   
public void render () {
    batch.setProjectionMatrix(camera.projection);
    batch.setTransformMatrix(camera.view);

    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    batch.begin();
    // draw a white background so we are able to see the black bars
    batch.setColor(1, 1, 1, 1);
    batch.draw(texture, -4096, -4096, 4096, 4096, 8192, 8192, 1, 1, 0, 0, 0, 16, 16, false, false);

    batch.setColor(1, 0, 0, 1);
    batch.draw(texture, 150, 100, 16, 16, 32, 32, 1, 1, 45, 0, 0, 16, 16, false, false);

    font.draw(batch, viewport.getClass().getSimpleName(), 150, 100);
    batch.end();

    if (viewport instanceof ScalingViewport) {
        // This shows how to set the viewport to the whole screen and draw within the black bars.
        ScalingViewport scalingViewport = (ScalingViewport)viewport;
        int screenWidth = Gdx.graphics.getWidth();
        int screenHeight = Gdx.graphics.getHeight();
        Gdx.gl.glViewport(0, 0, screenWidth, screenHeight);
        batch.getProjectionMatrix().idt().setToOrtho2D(0, 0, screenWidth, screenHeight);
        batch.getTransformMatrix().idt();
        batch.begin();
        float leftGutterWidth = scalingViewport.getLeftGutterWidth();
        if (leftGutterWidth > 0) {
            batch.draw(texture, 0, 0, leftGutterWidth, screenHeight);
            batch.draw(texture, scalingViewport.getRightGutterX(), 0, scalingViewport.getRightGutterWidth(), screenHeight);
        }
        float bottomGutterHeight = scalingViewport.getBottomGutterHeight();
        if (bottomGutterHeight > 0) {
            batch.draw(texture, 0, 0, screenWidth, bottomGutterHeight);
            batch.draw(texture, 0, scalingViewport.getTopGutterY(), screenWidth, scalingViewport.getTopGutterHeight());
        }
        batch.end();
        viewport.update(screenWidth, screenHeight, true); // Restore viewport.
    }
}
项目:martianrun    文件:GameStage.java   
public GameStage() {
    super(new ScalingViewport(Scaling.stretch, VIEWPORT_WIDTH, VIEWPORT_HEIGHT,
            new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT)));
    setUpCamera();
    setUpStageBase();
    setUpGameLabel();
    setUpMainMenu();
    setUpTouchControlAreas();
    Gdx.input.setInputProcessor(this);
    AudioUtils.getInstance().init();
    onGameOver();
}
项目:Missing_Words    文件:BaseScreen.java   
public BaseScreen(MissingWords missingWords) {
    this.missingWords = missingWords; // Conectamos el juego con la pantalla base
    this.myBatch = missingWords.getSB();

    /* 
     * Con Scaling.stretch ajustamos la aplicaci�n a la pantalla, estrechando
     * si es necesario.
     */
    viewport = new ScalingViewport(Scaling.stretch, 
            MissingWords.VIEWPORT_WIDTH , MissingWords.VIEWPORT_HEIGHT);

    stage = new Stage(viewport, myBatch);
}
项目:amatsukaze    文件:BaseGame.java   
protected void createHUD () {
    hud = new Stage(new ScalingViewport(Scaling.fit, PREF_HUDWIDTH, PREF_HUDHEIGHT));
    hudWidth = hud.getWidth();
    hudHeight = hud.getHeight();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));

    fpsLabel = new Label("FPS: 999", skin);
    hud.addActor(fpsLabel);

    vertexCountLabel = new Label("Vertices: 999", skin);
    vertexCountLabel.setPosition(0, fpsLabel.getTop());
    hud.addActor(vertexCountLabel);

    textureBindsLabel = new Label("Texture bindings: 999", skin);
    textureBindsLabel.setPosition(0, vertexCountLabel.getTop());
    hud.addActor(textureBindsLabel);

    shaderSwitchesLabel = new Label("Shader switches: 999", skin);
    shaderSwitchesLabel.setPosition(0, textureBindsLabel.getTop());
    hud.addActor(shaderSwitchesLabel);

    drawCallsLabel = new Label("Draw calls: 999", skin);
    drawCallsLabel.setPosition(0, shaderSwitchesLabel.getTop());
    hud.addActor(drawCallsLabel);

    glCallsLabel = new Label("GL calls: 999", skin);
    glCallsLabel.setPosition(0, drawCallsLabel.getTop());
    hud.addActor(glCallsLabel);

}
项目:ead    文件:EngineApplicationListener.java   
/**
 * Creates a Stage as in {@link Stage#Stage()}, but using
 * {@link PolygonSpriteBatch} instead of {@link SpriteBatch}
 * 
 * PolygonSpriteBatch must be used for
 * {@link es.eucm.ead.engine.components.renderers.SpineActor} 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;
}
项目:Wisper    文件:LoadingScreen.java   
@Override
public void resize(int width, int height) {
    WisperGame.Camera.zoom = 1f;
    WisperGame.Camera.updateViewport();

    ScalingViewport stageViewport = new ScalingViewport(
            Scaling.fit,
            WisperGame.VirtualViewport.getVirtualWidth(),
            WisperGame.VirtualViewport.getVirtualHeight(),
            WisperGame.Camera);

    stage.setViewport(stageViewport);
    stage.getViewport().update(width, height, true);
}
项目:Wisper    文件:WisperChooseMenu.java   
@Override
public void resize(int width, int height) {
    WisperGame.Camera.zoom = 1f;
    WisperGame.Camera.updateViewport();

    ScalingViewport stageViewport = new ScalingViewport(
            Scaling.fit,
            WisperGame.VirtualViewport.getVirtualWidth(),
            WisperGame.VirtualViewport.getVirtualHeight(),
            WisperGame.Camera);

    stage.setViewport(stageViewport);
    stage.getViewport().update(width, height, true);
    table.invalidateHierarchy();
}
项目:Wisper    文件:MainMenu.java   
@Override
public void resize(int width, int height) {
    WisperGame.Camera.zoom = 1f;
    WisperGame.Camera.updateViewport();

    ScalingViewport stageViewport = new ScalingViewport(
            Scaling.fit,
            WisperGame.VirtualViewport.getVirtualWidth(),
            WisperGame.VirtualViewport.getVirtualHeight(),
            WisperGame.Camera);

    stage.setViewport(stageViewport);
    stage.getViewport().update(width, height, true);
}
项目:Wisper    文件:SettingsMenu.java   
@Override
public void resize(int width, int height) {
    WisperGame.Camera.zoom = 1f;
    WisperGame.Camera.updateViewport();

    ScalingViewport stageViewport = new ScalingViewport(
            Scaling.fit,
            WisperGame.VirtualViewport.getVirtualWidth(),
            WisperGame.VirtualViewport.getVirtualHeight(),
            WisperGame.Camera);

    stage.setViewport(stageViewport);
    stage.getViewport().update(width, height, true);
    table.invalidateHierarchy();
}
项目:Wisper    文件:GameScreen.java   
@Override
public void resize(int width, int height) {
    WisperGame.Camera.zoom = Config.GAME_RATIO;
    WisperGame.Camera.updateViewport();

    ScalingViewport stageViewport = new ScalingViewport(
            Scaling.fit,
            WisperGame.VirtualViewport.getVirtualWidth(),
            WisperGame.VirtualViewport.getVirtualHeight(),
            WisperGame.Camera);

    stage.setViewport(stageViewport);
    stage.getViewport().update(width, height, true);
}
项目:MMORPG_Prototype    文件:Assets.java   
private static CustomStage createStage()
{
    return new CustomStage(new ScalingViewport(Scaling.stretch, Settings.GAME_WIDTH, Settings.GAME_HEIGHT));
}
项目:MMORPG_Prototype    文件:CustomStage.java   
public CustomStage(ScalingViewport scalingViewport)
{
    super(scalingViewport);
}
项目:space-travels-3    文件:SpaceTravels3.java   
@Override
public void create()
{
    services.setupPurchaseManager();

    MathUtils.random.setSeed(System.currentTimeMillis());
    ErrorHandlerProvider.addErrorHandler(new GdxErrorHandler());

    spriteBatch = new SpriteBatch(200);
    shapeRenderer = new ShapeRenderer();
    shapeRenderer.setAutoShapeType(true);
    menuViewport = new ScalingViewport(
        Scaling.stretch,
        Gdx.graphics.getWidth(),
        Gdx.graphics.getHeight(),
        new OrthographicCamera());
    gameViewport =
        new ExtendViewport(Constants.Visual.VIEWPORT_WIDTH, Constants.Visual.VIEWPORT_HEIGHT);
    gameViewport.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    Gdx.input.setCatchBackKey(true);

    AssMan.create();
    ScreenManager.create();
    UIManager.create();
    SoundManager.create();
    InputManager.create();
    MusicManager.create();

    MusicManager.playRandomMusic();

    if (Constants.General.IS_DEBUGGING)
    {
        Gdx.app.setLogLevel(Application.LOG_DEBUG);

        this.debugOverlay = new DebugOverlay();
    }
    else
    {
        Gdx.app.setLogLevel(Application.LOG_ERROR);
    }

    BackgroundScreen backgroundScreen = new BackgroundScreen();
    ScreenManager.addScreen(backgroundScreen);

    MenuScreen menuScreen = new MenuScreen();
    ScreenManager.addScreen(menuScreen);

    Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
}
项目:libgdxcn    文件:Stage.java   
/** Creates a stage with a {@link ScalingViewport} set to {@link Scaling#stretch}. The stage will use its own {@link Batch}
 * which will be disposed when the stage is disposed. */
public Stage () {
    this(new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), new OrthographicCamera()),
        new SpriteBatch());
    ownsBatch = true;
}
项目:gaiasky    文件:FovCamera.java   
public void initialize(AssetManager assetManager) {
    camera = new PerspectiveCamera(FOV, (float) (Gdx.graphics.getHeight() * GAIA_ASPECT_RATIO), Gdx.graphics.getHeight());
    camera.near = (float) CAM_NEAR;
    camera.far = (float) CAM_FAR;

    camera2 = new PerspectiveCamera(FOV, (float) (Gdx.graphics.getHeight() * GAIA_ASPECT_RATIO), Gdx.graphics.getHeight());
    camera2.near = (float) CAM_NEAR;
    camera2.far = (float) CAM_FAR;

    frustum2 = new Frustumd();

    fovFactor = FOV / 5f;

    /**
     * Fit viewport ensures a fixed aspect ratio. We set the camera field of
     * view equal to the satelltie's AC FOV and calculate the satellite
     * aspect ratio as FOV_AL/FOV_AC. With it we set the width of the
     * viewport to ensure we have the same vision as Gaia.
     */
    viewport = new FitViewport((float) (Gdx.graphics.getHeight() * GAIA_ASPECT_RATIO), Gdx.graphics.getHeight(), camera);
    viewport2 = new FitViewport((float) (Gdx.graphics.getHeight() * GAIA_ASPECT_RATIO), Gdx.graphics.getHeight(), camera2);

    /** Prepare stage with FP image **/
    fp = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("img/gaia-focalplane.png"))));
    fp_fov1 = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("img/gaia-focalplane-fov1.png"))));
    fp_fov2 = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("img/gaia-focalplane-fov2.png"))));

    fpstages = new Stage[3];

    Stage fov12 = new Stage(new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), new OrthographicCamera()), GlobalResources.spriteBatch);
    Image i = new Image(fp);
    i.setFillParent(true);
    i.setAlign(Align.center);
    i.setColor(0.3f, 0.8f, 0.3f, .9f);
    fov12.addActor(i);

    Stage fov1 = new Stage(new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), new OrthographicCamera()), GlobalResources.spriteBatch);
    i = new Image(fp_fov1);
    i.setFillParent(true);
    i.setAlign(Align.center);
    i.setColor(0.3f, 0.8f, 0.3f, .9f);
    fov1.addActor(i);

    Stage fov2 = new Stage(new ScalingViewport(Scaling.stretch, Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), new OrthographicCamera()), GlobalResources.spriteBatch);
    i = new Image(fp_fov2);
    i.setFillParent(true);
    i.setAlign(Align.center);
    i.setColor(0.3f, 0.8f, 0.3f, .9f);
    fov2.addActor(i);

    fpstages[0] = fov1;
    fpstages[1] = fov2;
    fpstages[2] = fov12;

    EventManager.instance.subscribe(this, Events.GAIA_LOADED, Events.COMPUTE_GAIA_SCAN_CMD);
}