Im trying to implement mechanics into my game where i can use the console to change reso with a command and go windowed to fullscreen what would be the correct approach to do that while making sure everything stays responsive and working as it should ?
someone told me in reddit “In my experience you can change window size at runtime but you can’t change whether you have a decorated window - either you start in fullScreen() or you get the window handle, no way around it afaik.”
This hack used to work in Processing 3 with FX2D renderer. Not sure about 4.
private PSurfaceFX surface;
/**
* JavaFX Canvas - an image that can be drawn on using a set of graphics
* commands. A node of the {@link #scene}.
*/
private Canvas canvas;
/**
* JavaFX Scene. Embedded in the {@link #stage} - the container for all other
* content (JavaFX nodes).
*/
protected Scene scene;
/**
* JavaFX Stage - the top level JavaFX container (titlebar, etc.).
*/
private Stage stage;
protected PSurface initSurface() {
surface = (PSurfaceFX) super.initSurface();
canvas = (Canvas) surface.getNative();
canvas.widthProperty().unbind(); // used for scaling
canvas.heightProperty().unbind(); // used for scaling
scene = canvas.getScene();
stage = (Stage) scene.getWindow();
return surface;
}
public void keyPressed() {
stage.setFullScreen(!stage.isFullScreen());
}
Does the code you provided support switching between different monitor sizes? I’m developing a game that needs to work seamlessly across all screen types. On my 2K monitor, everything works perfectly, but when I had others test it on smaller resolutions, they noticed some issues. For example, if the game has a grid as a background with a wall-like border around the edges, they see less of the grid, and the border is misaligned. Additionally, when they try to switch between fullscreen and windowed mode, which works fine for me, the game crashes with a “NullPointerException” error.
Do you have any idea if this is possible to do via processing ? Because i choose it to develop my game and i don’t want to re-make it another platform just because of this little thing.
So any type of help would be very much appreciated!
Hard to say, without seeing what happens … usually the fullscreen always matches the resolution the client has, but maybe you’ve some things hardcoded. If you want it to work with different resolutions you should carefully review you drawings not hardcoded in any way, but always relative to the design. Means don’t use s.th like hardcoded values (width - 20px) but use percentage values (width*.95, 95% of width). For the NullPointerException you should verify your game if there is one by mistake under specific circumstances…