Making my game work with different window sizes.
BlitzMax Forums/BlitzMax Programming/Making my game work with different window sizes.
| ||
I am making a simple retro game in a small window (320x240) and I want to give the player an option to set a x2 mode so that the window effectively becomes a 640x480 one. I will possible add x3 etc... too so I need things to be flexible. Now I know that I can use BMaxs SetScale capability to enlarge the graphics to fill this new, bigger window but what would be the best way to tackle the updating of my game objects so that they still move in the same way as they did at the smaller size? Should I be programming in this way, Scale=1 (1 for small window, 2 for x2 window) xpos=xpos+speed*scale ypos=ypos+speed*scale Would this be the best and most simple way to go about solving this problem? Another one would be to plot my objects at percentages instead of say, 10 pixels in I would place my object at 10% of the screen width this way when scaled up it would still be in the same place right? I`m not too sure on how to go about this though but I think that the idea is a good one. Any other solutions would be most appreciated. Jason. |
| ||
Here's the scaling class that I use. I always write for 800x600 then use this to project the screen to other resolutions. The game logic still runs in 800x600.Type tScaling Field xRatio:Float Field yRatio:Float Method New() xRatio = Float(GraphicsWidth()/800.0) yRatio = Float(GraphicsHeight()/600.0) End Method Method tX:Float(val:Float) Return val * xRatio End Method Method tY:Float(val:Float) Return val * yRatio End Method End Type Example of use: Graphics 800,600 '*MUST* do this before creating a tScaling object!! Global scaling:tScaling = New tScaling SetScale scaling.tX(1),scaling.tY(1) DrawImage myImage,scaling.tX(imageX),scaling.tY(imageY) Basically you use the tX() and tY() methods to translate everything to fit your resolution. You must apply these methods to all occurences of any scaling and drawing operations. |
| ||
Ah, very handy. Thanks a lot :) Jason. |
| ||
You could consider using a projection matrix. I believe Indiepath posted some example code on how to set it in both DX and OpenGL. Search for 'projection matrix' I'm sure something will come up. The advantage? You don't have to riddle your code with a bunch of multiplications and scaling operations. You just set your projection matrix to, let's say 800X600, then you code against that resolution but you can set the Graphics call to any resolution and it'll still render as if it was 800X600 but scaled and translated correctly. |
| ||
Thanks, I`ll take a look. BTW, is there a place that lists Indiepaths modules that are available for BMax? Infact, is there a list that has all released mods available for Max? Jason. |