Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (741)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (823)
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 - Resize  (Read 1624 times)
0 Members and 1 Guest are viewing this topic.
Offline SnowOwl

Senior Newbie


Medals: 2



« Posted 2015-02-10 15:04:06 »

Again hello guys,

Now I have a new problem.
As I mentioned in my Thread before (About the bad FPS), I've made my own Snake project.
That project should have 3 Screens. The "MenuScreen", "GameScreen" and "HighscoreScreen".

My Main Class (Called Snake2D) extends Game. In that class I'd initialise my OrthographicCamera.
   camera = new OrthographicCamera(600, 400);
        camera.setToOrtho(false, 600, 400);

As you can see, the size of the window should be 600x400.
Now for the "GameScreen" I want to resize the window to 200x200.
In the tutorials from the wiki of LibGDX i've read something about the viewport and that I should change the viewport to resize my window.
But how can i do this?

Thats my Main-Class.
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  
45  
46  
47  
public class Snake2D extends Game {
   
   public SpriteBatch batch;
   public BitmapFont font;
   
   private OrthographicCamera camera;
   private Viewport viewport;
   
   @Override
   public void create () {
      batch = new SpriteBatch();
      font = new BitmapFont();
     
      camera = new OrthographicCamera(600, 400);
        camera.setToOrtho(false, 600, 400);
       
      this.setScreen(new MenuScreen(this));
   }

   @Override
   public void render () {
      Gdx.gl.glClearColor(1, 1, 1, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
      super.render();
   }
     
   @Override
   public void dispose() {
      batch.dispose();
      font.dispose();
   }

   @Override
   public void pause() {
      super.pause();
   }

   @Override
   public void resume() {
      super.resume();
   }

   @Override
   public void resize(int width, int height) {
      camera.setToOrtho(false, width, height);
      camera.update();
   }


And thats the part when I want to resize the window
1  
2  
3  
4  
5  
6  
7  
8  
         if(Gdx.input.getX() >= (Gdx.graphics.getWidth()-300)/2 && Gdx.input.getX() <= (Gdx.graphics.getWidth())/2+150){
            if(Gdx.input.getY() >= 85 && Gdx.input.getY() <= 185){
               Gdx.graphics.setDisplayMode(200, 200, false);
               game.resize(200, 200);
               dispose();
               game.setScreen(new GameScreen(game,name));
            }
         }


You can imagine... that it's not working Cheesy
Can you help? Sad
Offline craftm

JGO Coder


Medals: 15
Projects: 1


_Keep Trying


« Reply #1 - Posted 2015-02-10 16:07:47 »

1 - Gdx.input.getX()/getY() get the touched input "X/Y".

2 - You can use different types of viewports: https://github.com/libgdx/libgdx/wiki/Viewports

E.g using Stretch Viewport to 800x480:
1  
2  
3  
4  
5  
6  
7  
8  
9  
//Camera
camera = new OrthographicCamera(800, 480);

//Viewport
viewport = new StretchViewport(width, height,camera);
viewport.apply();

//If you are using Stage
stage = new Stage(new StretchViewport(width, height));


If you have precision touch events, you need to convert the device screen X and Y to game screen X and Y.

_ Wink
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (110 views)
2017-09-30 02:57:34

theagentd (146 views)
2017-09-26 18:23:31

cybrmynd (245 views)
2017-08-02 12:28:51

cybrmynd (241 views)
2017-08-02 12:19:43

cybrmynd (240 views)
2017-08-02 12:18:09

Sralse (254 views)
2017-07-25 17:13:48

Archive (872 views)
2017-04-27 17:45:51

buddyBro (1024 views)
2017-04-05 03:38:00

CopyableCougar4 (1574 views)
2017-03-24 15:39:42

theagentd (1373 views)
2017-03-24 15:32:08
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!