Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
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 textures  (Read 914 times)
0 Members and 1 Guest are viewing this topic.
Offline Zeta

Junior Devvie


Medals: 1
Exp: 1 year



« Posted 2013-10-03 20:11:38 »

When I run the application on desktop every texture is in right position right size, but when i run it on Andorid device
some of the textures wont show because they are out of bounds.

How can i fix the resolution that it would be the same on both devices

application runs on 1024x786 on desktop.

A clever person solves a problem. A wise person avoids it. -Albert Einstein
Offline Andre Lopes
« Reply #1 - Posted 2013-10-03 20:16:16 »

When I run the application on desktop every texture is in right position right size, but when i run it on Andorid device
some of the textures wont show because they are out of bounds.

How can i fix the resolution that it would be the same on both devices

application runs on 1024x786 on desktop.

I want to add another question in top of that question if i may!
I have the same question than Zeta, plus, when i run on android or in another computer with another resolution, does that question of ZETA still applies?

i mean, Zeta, you use this as well :

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 static void main(String[] args) {

       
        // create the listener that will receive the application events
        ApplicationListener listener = new MainView();
       
        // define the window's title
        String title = "Alpha Version";

        // define the window's size
        width = 800;
        height = 600;

        // whether to use OpenGL ES 2.0
        boolean useOpenGLES2 = true;

        // create the game
        System.setProperty("user.name", "EnglishWords");
        new LwjglApplication(listener, title, width, height, useOpenGLES2);
       
    }

    /**
     * Returns the best Size to the Screen!
     */

    public void getAvaiableScreenSize() {
    }


Right?
So we will need to worry with textures too? Or we can just adjust the camera? I think we just need to adjust the camera Zeta! I think dermetfan already helped me to mess with @resize() method...
Offline Zeta

Junior Devvie


Medals: 1
Exp: 1 year



« Reply #2 - Posted 2013-10-04 12:54:48 »

Quote
Right?
So we will need to worry with textures too? Or we can just adjust the camera? I think we just need to adjust the camera Zeta! I think dermetfan already helped me to mess with @resize() method...

I've tried to do everything with camera just cant get it to work. I hope someone has solution for this. Or is it just better to do Android and desktop versions separately?

A clever person solves a problem. A wise person avoids it. -Albert Einstein
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline xsvenson
« Reply #3 - Posted 2013-10-04 13:03:48 »

No, You don't need to do anything separately. Libgdx will do that for You
Here's a link talking about the camera and how it works:
https://code.google.com/p/libgdx/wiki/ProjectionViewportCamera

To sum it up, by default, the viewport is a rectangle -1 to +1 on both x and y. When You render Your texture at (-0.5,-0.5) with a size of 0.5, then it will be in the middle of the screen regardless of the screen. However, depending on the screen size, it might be stretched or the opposite.

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline Zeta

Junior Devvie


Medals: 1
Exp: 1 year



« Reply #4 - Posted 2013-10-04 21:42:40 »

No, You don't need to do anything separately. Libgdx will do that for You
Here's a link talking about the camera and how it works:
https://code.google.com/p/libgdx/wiki/ProjectionViewportCamera

To sum it up, by default, the viewport is a rectangle -1 to +1 on both x and y. When You render Your texture at (-0.5,-0.5) with a size of 0.5, then it will be in the middle of the screen regardless of the screen. However, depending on the screen size, it might be stretched or the opposite.

not sure if im stupid. I cant still get it to work. here's what i've done

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  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
   Stage stage;
   Texture backgroundTexture, titleTexture;
   Sprite background, title;
   SpriteBatch batch;
   Music bgm;
   private OrthographicCamera camera;

   @Override
   public void render(float delta) {
      camera.update();
     
      batch.begin();
      background.draw(batch);
      title.setBounds(Gdx.graphics.getWidth()/3.5f,Gdx.graphics.getHeight()/1.5f , title.getWidth(), title.getHeight());
      title.draw(batch);
      batch.end();
     
   }

   @Override
   public void resize(int width, int height) {
      float aspectRatio = (float) width / (float) height;
        camera = new OrthographicCamera(2f * aspectRatio, height);
   }

   @Override
   public void show() {
      backgroundTexture = new Texture(Gdx.files.internal("img/bgMain.jpg"));
      background = new Sprite(backgroundTexture);
      background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
     
      titleTexture = new Texture(Gdx.files.internal("img/MenuTitle.png"));
      title = new Sprite(titleTexture);
     
     
     
      batch = new SpriteBatch();
     
      bgm = Gdx.audio.newMusic(Gdx.files.internal("music/MenuBgm.mp3"));
      bgm.setLooping(true);
      bgm.setVolume(0.5f);
      bgm.play();
     
   }


Do i have to use meshes or am i just stupid  Smiley. Just keep in mind this is my first libgdx project.

A clever person solves a problem. A wise person avoids it. -Albert Einstein
Offline xsvenson
« Reply #5 - Posted 2013-10-04 23:40:28 »

1  
title.setBounds(Gdx.graphics.getWidth()/3.5f,Gdx.graphics.getWidth()/1.5f , title.getWidth(), title.getHeight())

I think the second argument here should be getHeight() not getWidth(). Also You don't need to set the bounds on every frame. It should be enough to set them in the create() method;

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline Zeta

Junior Devvie


Medals: 1
Exp: 1 year



« Reply #6 - Posted 2013-10-06 16:13:29 »

I still have a problem keeping the aspect ratio  Undecided. Thanks for your help thought.

A clever person solves a problem. A wise person avoids it. -Albert Einstein
Offline Zeta

Junior Devvie


Medals: 1
Exp: 1 year



« Reply #7 - Posted 2013-10-08 18:59:54 »

How can i use pixel density in libgdx that it will resize/ scale the textures in any phone.
all i could find was getPixelDensity();. Can i use this somehow or have i undestanded pixel density completely wrong?


Thank you. (didnt want to make o new topic since its relevant to this one).

A clever person solves a problem. A wise person avoids it. -Albert Einstein
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.

xFryIx (62 views)
2014-11-13 12:34:49

digdugdiggy (41 views)
2014-11-12 21:11:50

digdugdiggy (36 views)
2014-11-12 21:10:15

digdugdiggy (30 views)
2014-11-12 21:09:33

kovacsa (53 views)
2014-11-07 19:57:14

TehJavaDev (56 views)
2014-11-03 22:04:50

BurntPizza (55 views)
2014-11-03 18:54:52

moogie (70 views)
2014-11-03 06:22:04

CopyableCougar4 (71 views)
2014-11-01 23:36:41

DarkCart (156 views)
2014-11-01 14:51:03
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!