Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bjon045 opened this issue Feb 26, 2023 · 0 comments
Open

Comments

@bjon045
Copy link

bjon045 commented Feb 26, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant