0
\$\begingroup\$

I'm creating a simple 2D platformer and I have problem with my camera y position when I enter full screen mode. But first here's my code

screenY = Gdx.graphics.getHeight();

public void updateCamera(){
        camera.position.x += (player1.getHitBox().x - camera.position.x);
        if(screenY < player1.getHitBox().getY() && player1.getHitBox().getY() > (screenY - Gdx.graphics.getHeight())){
            screenChanger++;
        }else if(player1.getHitBox().getY() < (screenY - Gdx.graphics.getHeight())){
            screenChanger--;
        }
        screenY = Gdx.graphics.getHeight() * screenChanger;
        camera.position.y = (screenY - screenY/2);
        camera.update();

        System.out.println(Gdx.graphics.getHeight() + " " + screenY);
    }

So here's my results: 1) When I start the game all works fine enter image description here

2) But when I enter to fullscreen here what I get enter image description here

3) here how it looks when I zoom out my camera enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Have a read through this. \$\endgroup\$ Commented Apr 26, 2015 at 21:11

1 Answer 1

1
\$\begingroup\$

When you "enter full-screen", the base window's border is removed and it is re-sized and moved such that its' ClientBounds == ScreenBounds. When this occurs, the Device is destroyed ("lost"), and needs to be recreated. At the same time, the back-buffer and any other textures or rendertargets that should be "full-screen" must also be re-created with the new size. Recreating them with the wrong dimensions will cause magnification and/or minification artifacts (pixelation, looking "crushed" or "smushed", etc.).

As a function of re-sizing the rendertargets, the gl_Viewport describing the portion of the render target to use may also need to be updated.

As a function of updating the Viewport, the Camera may also need to use different matrices. For 2D, the View matrix is typically Identity, so you really only need to update the camera's Projection to fit "more world" into the texture. The World matrix is still just World.

LibGDX wraps all of the above into the Viewport class (low-level usage details).

Have a read through this (high-level usage details). – StrongJoshua

\$\endgroup\$
2
  • \$\begingroup\$ Thanks! But still I have some scaling problems or others I don't know because then my background position is still bad... \$\endgroup\$ Commented Apr 28, 2015 at 19:51
  • \$\begingroup\$ @user3334375, please add an updated screenshot. \$\endgroup\$
    – Jon
    Commented May 3, 2015 at 6:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .