Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (527)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (594)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [SOLVED] LibGDX - Window contents overstrech upon resizing  (Read 823 times)
0 Members and 1 Guest are viewing this topic.
Offline Zegrento7

Junior Newbie





« Posted 2013-09-15 19:54:24 »

Hi everybody!
I'm new to libgdx and to this great forum so please don't hurt me if I do something stupid..

Anyway, I'm making a logic circuit simulator for desktop and mostly Android, and I ran into a problem which didn't see anywhere on the Internet:

Here's the program with it's default size:

This is how it should look at all times.

And this is how it looks if I make the window smaller:


The UI should adjust to the new size, but it shrinks too much. The controls work OK (a click in the blackness in the bottom right corner toggles the options panel).

If the program starts with a different default value, it looks well only on that size.

I searched the Internet about this, but nothing came up ( or I'm just too blind  Tongue ).

I know it's a stupid problem that I should be able to solve, but as I stated, I'm new to libGDX.

Oh, and the problem probably has to do something with the fact that I don't use cameras.

Any help would be awesome and thanks in advance!
Btw: This forum ROCKS!!
Offline namrog84

JGO Ninja


Medals: 46
Projects: 4


Keep programming!


« Reply #1 - Posted 2013-09-15 20:03:33 »

Do you have something in your method resize code?  post it?

Maybe you need to readjust your camera or something else, whenever the screen resizes?

Are you defining based upon a fixed value, or Gdx.getGraphics.getWidth()/.getHeight() ?





"Experience is what you get when you did not get what you wanted"
Offline BenningtonHD

Junior Devvie


Projects: 1



« Reply #2 - Posted 2013-09-15 20:14:02 »

Quote
I'm new to libgdx and to this great forum so please don't hurt me if I do something stupid..

Muhahahaha
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Zegrento7

Junior Newbie





« Reply #3 - Posted 2013-09-15 20:20:02 »

Wow, that was quick!

My resize method is currently empty, and there are no cameras to readjust(or is there a default camera?). The sprites' positions are defined using getWidth() and getHeight().
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 139
Projects: 4
Exp: 3 years



« Reply #4 - Posted 2013-09-16 01:19:01 »

If you can click in black space to have the button respond, it probably has more to do with how you're rendering the diagram...post a snippet maybe?
Offline Cero
« Reply #5 - Posted 2013-09-16 02:19:06 »

Oh, and the problem probably has to do something with the fact that I don't use cameras.
Yes sir. May we see some of the init code ?
Im no opengl expert, but its clearly a viewport issue.

Offline SHC
« Reply #6 - Posted 2013-09-16 03:43:58 »

I don't know about libGdx but here's how to change the viewport in LWJGL. You can find a similar mechanism in libGdx.

1  
2  
3  
4  
public void resized()
{
    glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
}

This sets the viewport to the window space completely stretching the bounds you specify in the Orthographic Camera.

Offline Zegrento7

Junior Newbie





« Reply #7 - Posted 2013-09-16 04:56:13 »

Yes sir. May we see some of the init code ?
Im no opengl expert, but its clearly a viewport issue.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
   public void init() {
      font = new BitmapFont(Gdx.files.internal("gfx/font.fnt"), false);
      font.setColor(0.9254902F, 0.9254902F, 0.9254902F, 1);
     
      inactive = new Texture(Gdx.files.internal("gfx/CABLE-OFF.png"));
      scrollUp = new Texture(Gdx.files.internal("gfx/UP.png"));
      scrollDown = new Texture(Gdx.files.internal("gfx/DOWN.png"));

      bgtex = new Texture(Gdx.files.internal("gfx/UIBG.png"));
      bgsel = new Texture(Gdx.files.internal("gfx/UISEL.png"));
     
      left[0] = new Texture(Gdx.files.internal("gfx/NOT.png"));
      left[1] = new Texture(Gdx.files.internal("gfx/AND.png"));
      left[2] = new Texture(Gdx.files.internal("gfx/OR.png"));
      left[3] = new Texture(Gdx.files.internal("gfx/XOR.png"));
      left[4] = new Texture(Gdx.files.internal("gfx/SWITCH-OFF.png"));
      left[5] = new Texture(Gdx.files.internal("gfx/LIGHT-OFF.png"));
     
      right[0] = new Texture(Gdx.files.internal("gfx/UIOPT.png"));
      right[1] = new Texture(Gdx.files.internal("gfx/SWITCH-ON.png"));
     
      options[0] = new Texture(Gdx.files.internal("gfx/UNDO.png"));
      options[1] = new Texture(Gdx.files.internal("gfx/SAVE.png"));
      options[2] = new Texture(Gdx.files.internal("gfx/LOAD.png"));

      sb = new SpriteBatch();
   }


I don't know about libGdx but here's how to change the viewport in LWJGL. You can find a similar mechanism in libGdx.

1  
2  
3  
4  
public void resized()
{
    glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
}


I found
1  
 Gdx.gl20.glViewport(0, 0, width, height); 
, but it didn't do a thing.
Thanks anyways!

If you can click in black space to have the button respond, it probably has more to do with how you're rendering the diagram...post a snippet maybe?

1  
2  
3  
4  
5  
6  
public void render() {
   sb.begin();
   sb.draw(bgtex, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
   //Draw rest of the UI
   sb.end();
}
Offline SHC
« Reply #8 - Posted 2013-09-16 05:04:22 »

Try making an orthographic camera. There is a wiki page here. https://code.google.com/p/libgdx/wiki/OrthographicCamera

Offline Zegrento7

Junior Newbie





« Reply #9 - Posted 2013-09-16 14:32:45 »

Try making an orthographic camera. There is a wiki page here. https://code.google.com/p/libgdx/wiki/OrthographicCamera

Ok, i'll give that a try. Thanks for the link!

EDIT:
1  
cam.setToOrtho(false, width, height);

WORKED LIKE A CHARM!! THANK YOU EVERYBODY!!  Grin
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jimmt
« League of Dukes »

JGO Kernel


Medals: 139
Projects: 4
Exp: 3 years



« Reply #10 - Posted 2013-09-16 16:35:15 »

Instead of initialzing that many textures, use a TextureAtlas or (if left is supposed to be an animation) Animation.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

PocketCrafter7 (14 views)
2014-11-28 16:25:35

PocketCrafter7 (9 views)
2014-11-28 16:25:09

PocketCrafter7 (10 views)
2014-11-28 16:24:29

toopeicgaming1999 (76 views)
2014-11-26 15:22:04

toopeicgaming1999 (67 views)
2014-11-26 15:20:36

toopeicgaming1999 (17 views)
2014-11-26 15:20:08

SHC (30 views)
2014-11-25 12:00:59

SHC (28 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (28 views)
2014-11-24 19:59:16
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!