how to correctly change screen size

Asked by At

I am a novice of libGDX and I want to make a simple graphical interface I soon found myself in difficulty due to the lack of a graphic editor. In the end I found Overlap2D on Google, which I was able to include it in my project and to run it. However, I have two questions about this framework:

1) Is it abandoned? Is it advisable to use it or will it be abandoned soon?

2) I created a simple screen with four images:

https://imgur.com/XeJhIFP

If I increase the size of the screen, what happens is that the drops do not position themselves according to the four previous corners but remain where they are.

https://imgur.com/fKoimNU

I'll post the code I wrote. How should i do?

thank you so much

package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL20;

import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.utils.viewport.ExtendViewport;
import com.badlogic.gdx.utils.viewport.FillViewport;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.uwsoft.editor.renderer.SceneLoader;
import com.uwsoft.editor.renderer.resources.ResourceManager;


public class MyGdxGame extends ApplicationAdapter {
    private SceneLoader sceneLoader;
        private ResourceManager rm;
    private Viewport viewport;
    private Camera camera;
    @Override
    public void create () {

        rm = new ResourceManager();
        rm.initAllResources();
    camera = new OrthographicCamera();
    viewport = new ExtendViewport(480 , 800, camera);
    viewport.apply();
    sceneLoader = new SceneLoader(rm);
    sceneLoader.loadScene("MainScene", viewport);
}

@Override
public void render () {
    Gdx.gl.glClearColor(0, 0, 0, 1);
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
    camera.update();
    sceneLoader.getEngine().update(Gdx.graphics.getDeltaTime());
}

@Override
public void resize(int width, int height) {
    viewport.update(width, height);

}

}

1 Answers

0
wietze On

1) Is it abandoned? Is it advisable to use it or will it be abandoned soon?

If you are making a tile based game i would really recommend tiled : https://www.mapeditor.org/

It seems that further development of overlap2D has stopped but that shouldn't be a reason not to use it. Use that if you are making a game which contains platforms of different sizes and angles.

2) I created a simple screen with four images:

You are using ExtendViewport. This viewport keeps the world aspect ratio by axtending the world in one direction. In your second image you can clearly see that the world is extended to the right. I think what you want is to use FitViewport, this will always maintain the aspect ratio of the virtual screen size, while scaling it as much as possible to fit the entire screen.