Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Libgdx Resizing Problem  (Read 6034 times)
0 Members and 1 Guest are viewing this topic.
Offline Baseball435

Senior Newbie


Projects: 1



« Posted 2013-01-17 02:24:15 »

I am trying to fill the resize function that comes with Libgdx to fit all of the android screens.

I have been searching for a solution for about an hour and a half but have none. The best solution so far is this tutorial: http://www.java-gaming.org/index.php?topic=25685.0 but when I run it on my Galaxy S3 the buttons are really tiny and just overall the whole game is tiny where on the desktop version it is big and the way I want it to be. My resize code right now is:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
        @Override
   public void resize(int width, int height) {
        float aspectRatio = (float)width/(float)height;
        float scale = 2f;
        Vector2 crop = new Vector2(0f, 0f);
        if(aspectRatio > ASPECT_RATIO)
        {
            scale = (float)height/(float)VIRTUAL_HEIGHT;
            crop.x = (width - VIRTUAL_WIDTH*scale)/2f;
        }
        else if(aspectRatio < ASPECT_RATIO)
        {
            scale = (float)width/(float)VIRTUAL_WIDTH;
            crop.y = (height - VIRTUAL_HEIGHT*scale)/2f;
        }
        else
        {
            scale = (float)width/(float)VIRTUAL_WIDTH;
        }

        float w = (float)VIRTUAL_WIDTH*scale;
        float h = (float)VIRTUAL_HEIGHT*scale;
        viewport = new Rectangle(crop.x, crop.y, w, h);
    }

My render code is:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
        @Override
   public void render() {
      // update camera
        camera.update();

        // set viewport
        Gdx.gl.glViewport((int) viewport.x, (int) viewport.y,
                          (int) viewport.width, (int) viewport.height);

        // clear previous frame
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
       
       ScreenManager.updateScreen();
       
       sb.begin();
       ScreenManager.renderScreen(sb);
       sb.end();
   }

And my variables are:
1  
2  
3  
4  
5  
6  
7  
8  
9  
        private static final int VIRTUAL_WIDTH = 600;
   private static final int VIRTUAL_HEIGHT = 800;
   private static final float ASPECT_RATIO = (float)VIRTUAL_WIDTH/(float)VIRTUAL_HEIGHT;
   
   public static BitmapFont FONT;
   
   private OrthographicCamera camera;
   private Rectangle viewport;
   private SpriteBatch sb;

Like I said, when I run the desktop version it works fine but when I run it on my Galaxy S3, the game is zoomed out a lot, and it crops out the tops and sides of the game which is not what I want at all. If someone could help me that would be great. Thanks!
Offline BluePuppy

Junior Newbie





« Reply #1 - Posted 2013-01-27 17:48:32 »

The method resize() is never called on Android.
Offline BluePuppy

Junior Newbie





« Reply #2 - Posted 2013-01-27 17:50:20 »

You should draw your game in function of Gdx.getWidth() and Gdx.getHeight().

I work like that and that works perfectly but i'm not sure at all that's the best method.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline wreed12345

JGO Knight


Medals: 25
Projects: 2
Exp: 2 years


http://linebylinecoding.blogspot.com/


« Reply #3 - Posted 2013-01-27 19:28:11 »

As BluePuppy said thats how i do it on android

1  
2  
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

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.

rwatson462 (35 views)
2014-12-15 09:26:44

Mr.CodeIt (26 views)
2014-12-14 19:50:38

BurntPizza (54 views)
2014-12-09 22:41:13

BurntPizza (87 views)
2014-12-08 04:46:31

JscottyBieshaar (49 views)
2014-12-05 12:39:02

SHC (64 views)
2014-12-03 16:27:13

CopyableCougar4 (67 views)
2014-11-29 21:32:03

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

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

toopeicgaming1999 (34 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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
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!