Orientation Change... Change?

Anything libgdx related goes here!

Orientation Change... Change?

Postby Wavesonics » Tue Dec 28, 2010 12:10 am

I wrote a simple little game a while back but never finished it.
It was using libGDX 0.53 I believe. In last couple days I've been updating it to work with the new 0.81 release.

So first off, nice changes :D

But I'm having trouble handling orientation changes.

Where as before orientation changes seemed to work fairly auto-magically, now the graphic just stretch and look horrid when I go from portrait to land scape or visa versa.

Is there something extra I need to do now?
Wavesonics
 
Posts: 102
Joined: Sun Jul 11, 2010 5:10 am

Re: Orientation Change... Change?

Postby aksarfevad » Tue Dec 28, 2010 1:46 am

If you are just trying to prevent changes in orientation, see this post .

I'm not sure how that old of a version handled orientation changes. Nowadays, in your ApplicationListener, you need to override
Code: Select all
public void resize(int width, int height)
which will get called every time your viewport changes size (e.g. orientation changes on android, window resizes on the desktop).
aksarfevad
 
Posts: 275
Joined: Fri Nov 19, 2010 4:19 am

Re: Orientation Change... Change?

Postby Wavesonics » Tue Dec 28, 2010 3:36 pm

No I'm not trying to prevent it.

It seems like the view-port isn't actually resizing, it seems like it's keeping the same dimensions and just stretching & shrinking to fit the new orientation. This isn't something I would have to handle in my ApplicationListener::resize() method, or is it? (Resizing the viewport that is)
Wavesonics
 
Posts: 102
Joined: Sun Jul 11, 2010 5:10 am

Re: Orientation Change... Change?

Postby aksarfevad » Tue Dec 28, 2010 7:05 pm

Well... it depends on what you use. For example, if you are using a SpriteBatch, you change the projection matrix. E.G. from HelloWorld.java :

Code: Select all
        @Override public void resize (int width, int height) {
                spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
                textPosition.set(0, 0);
        }


If you are using a camera, you can use something like:
Code: Select all
camera.setViewport( Gdx.graphics.getWidth(), Gdx.graphics.getHeight() );
aksarfevad
 
Posts: 275
Joined: Fri Nov 19, 2010 4:19 am

Re: Orientation Change... Change?

Postby mzechner » Tue Dec 28, 2010 7:45 pm

And you'll of course have to call glViewport in case of a screen change if i'm not mistaken. The camera's should do that automatically, the spritebatch won't do it.
mzechner
Site Admin
 
Posts: 4879
Joined: Sat Jul 10, 2010 3:50 pm

Re: Orientation Change... Change?

Postby Wavesonics » Tue Dec 28, 2010 10:30 pm

Ah got ya, I haven't done that on the sprite batch yet. I'll give that a try.

I'm not using any camera right now.

Because so little of this higher level stuff existed in 0.50 i wrote a lot of my own... My next project will take advantage of it all I guess.
Wavesonics
 
Posts: 102
Joined: Sun Jul 11, 2010 5:10 am


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest