mini2Dx/mini2Dx

InputAdapter does not appear to honor Viewport when game window is resized.

Opened this issue · 0 comments

Running Mini2dx 2.0.0-beta17. Java 17. Windows 10. Screenbased game using Lwjgl3Mini2DxConfig.

If I resize the window after an InputAdapter has been created it appears the X/Y coordinates passed into the method are not projected onto the viewport coordinate system like they are before the resize. Code is below.


public class DesktopLauncher {
    public static void main(String[] arg) {
	Lwjgl3Mini2DxConfig config = new Lwjgl3Mini2DxConfig(SampleGame.GAME_IDENTIFIER);
	config.useVsync(true);
	config.setWindowedMode(Constants.SCREEM_WIDTH, Constants.SCREEM_HEIGHT);
	new DesktopMini2DxGame(new SampleGame(), config);
    }
}

public class SampleGame extends ScreenBasedGame {
    public static final String GAME_IDENTIFIER = "nz.co.SampleGame";

    private FitViewport fitViewport;

    @Override
    public void initialise() {
	fitViewport = new FitViewport(Constants.SCREEM_WIDTH, Constants.SCREEM_HEIGHT);

	addScreen(new IntroScreen());
	addScreen(new StartScreen());
	addScreen(new GameOptionsScreen());
	addScreen(new MainMapScreen());
    }

    @Override
    public int getInitialScreenId() {
	return Screen.INTRO_SCREEN.getScreenId();
    }

    @Override
    public void render(Graphics g) {
	fitViewport.apply(g);
	super.render(g);
    }

    @Override
    public void resize(int width, int height) {
	fitViewport.onResize(width, height);
	super.resize(width, height);
    }
}

public class Constants {

    public static final int SCREEM_WIDTH = 1280;

    public static final int SCREEM_HEIGHT = 720;

}


Then in one of the screens create an InputAdapter as follows.

@Override
public void postTransitionIn(Transition transitionIn) {
Mdx.input.setInputProcessor(new InputAdapter() {

    @Override
    public boolean touchDown(int screenX, int screenY, int pointer, int button) {
	System.out.println("screenX: " + screenX);
        System.out.println("screenY: " + screenY);
	return super.touchDown(screenX, screenY, pointer, button);
    }

});
super.postTransitionIn(transitionIn);
}

Output before resize:
screenX: 1274
screenY: 712

and after resize (note: cooridinates are outside viewport size):
screenX: 2547
screenY: 1366