Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
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 1888 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  
 
 

 
EgonOlsen (1597 views)
2018-06-10 19:43:48

EgonOlsen (1699 views)
2018-06-10 19:43:44

EgonOlsen (1152 views)
2018-06-10 19:43:20

DesertCoockie (1580 views)
2018-05-13 18:23:11

nelsongames (1180 views)
2018-04-24 18:15:36

nelsongames (1703 views)
2018-04-24 18:14:32

ivj94 (2470 views)
2018-03-24 14:47:39

ivj94 (1685 views)
2018-03-24 14:46:31

ivj94 (2769 views)
2018-03-24 14:43:53

Solater (907 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!