0

I'm making a small game of the single-screen, shoot'em up/platformer sort with javafx, and i wish to make it work on screens with different resolutions. All my graphics are made of java shapes in a single Pane, whose positions on the screen are determined by coordinates which correspond to pixels. I'd need the gameplay to be consistent accross platforms, but I'm having trouble since, for example, a velocity of 10 pixels per unit time is faster on a smaller resolution.

The only solution I can think of with what I know is multiplying everything by a ratio between some constant and the resolution, but that seems a little sloppy, so I'm wondering if there's a better way. Could I, for instance, have the game run "internally" at a constant resolution to get the math consistent, then scale that to fit whatever screen the player is using?

Tom
  • 1
  • There are some related questions you could review: [JavaFX fullscreen](http://stackoverflow.com/questions/16606162/javafx-fullscreen) and [javafx automatic resizing and button padding](http://stackoverflow.com/questions/23229149/javafx-automatic-resizing-and-button-padding). In general the question too broad to answer definitively here as numerous approaches might provide a solution (e.g. you could scale the scene uniformly to fill available area or you could use a reactive layout design to change the layout dynamically based on both resolution and aspect ratio). – jewelsea Nov 17 '16 at 19:33

1 Answers1

0

Your solution of rendering at a constant scale resolution is generally how it is handled with different aspect ratios getting different treatments in emulators and such. Sometimes revealing more of the background image or adding side bars so the playable space remains constant and it is only upscaled for view.

In general though the way this is best accomplished with modern hardware is probably abstracting away 'pixels' entirely from your game layer. Your game should move '10', 10 what? 10 units. Then when your rendering engine comes in behind it the renderer knows 10 units = 10px or 20px or whatever scale factor. That way your game pieces only worry about playing the game, while your rendering layer worries about how to write it all to image. Then you just have to worry about handling different aspect ratios which you really have to account for no matter what.

Typically with games the only time I use pixels directly is with UI elements.

Chase R Lewis
  • 2,119
  • 1
  • 22
  • 47