views:

100

answers:

3

I'm looking to make a relatively simple game using solely graphics primitives (Arcs, Lines, Polygons, etc.).

I started doing this in C# by drawing to a Panel, but right now I'm hung up on how all the scaling works in terms of keeping the proportions the same when changing resolutions. Does anyone have any advice and / or tips on how to do something like this?

A: 

Not really a helpful answer but, don't use WinForms!!

If you want a good gaming platform, use DirectX, or XNA Game Studio.

Richard J. Ross III
Damn right it's not really helpful. WinForms is fine for simple little games, and it sounds like that's the goal here. Using DirectX means having to learn about surfaces, pixel formats, and a million other plumbing details just to draw a dot on the screen. And then, is there a line- or arc-drawing function that doesn't involve 3D graphics calls? And whether there is or not, *how does this address the actual problem?*
cHao
Have you actually used DirectX??? The API is horrible... I wouldn't recommend it to a beginner.
jheriko
No I haven't used dx much, but I use XNA a.lot, and it's pretty easy to understand, though you need to make your own methods for drawing primitives....
Richard J. Ross III
+2  A: 

There are two options:

1 - Scale everything so that it is sized at a certain percentage of the screen/window. For example, if you want your object to be 1/4 of the screen, then it's width is ScreenWidth/4 and height is ScreenHeight/4. The problem with this technique is that a screen's aspect ratio may make things short and fat or tall and wide. Usually this is addressed by determining one dimension and then using the screen's aspect ratio to determine the other dimension. Ie, Width=Height*AspectRatio.

2 - Make everything the same physical dimension. For example, you may want an object to appear exactly 1" by 1". You can use the screen's resolution (dots per inch) to scale your drawings accordingly. The problem with this is that while it may work well for 'average' sized screens, images may be too small on large screens or too large on small screens.

Most games use technique #1 (with compensation made for the aspect ratio). AR was not always a big deal, but now with widescreen monitors being so popular, it's almost required.

Also, like Richard said, WinForms is not great for games (except minesweeper!), but probably okay for teaching yourself.

Marc Bernier
"AR was not always a big deal, but now with widescreen monitors being so popular, it's almost required." I disagree. With resizeable windows you always have to take this into account unless you want your circles to turn into ellipses and reveal your lack of experience. But good answer overall.
Jared Updike
Civilization IV displays resource circles as ovals on my widescreen monitor, they finally fixed the problem in Civilization V. I always hated seeing those ovals, I thought their programmers were smarter than that.
Marc Bernier
Actually aspect ratio is non-trivial to solve - if you see circles as ovals, chances are the resolution you needed was not supported, or whatever you chose was wrong. Even so there is no way for the game to know the aspect ratio of the monitor or the pixels afaik, - supporting every resolution is nice and easy to do in code, but its a lot easier to not do it at all.
jheriko
also, AR correction has always been a big deal to those who care - its the sort of thing you just do all the time if you really care about quality... its certainly not new to do it, just new that you can't get away with not doing it.
jheriko
I should have said 'varying aspect ratio'. Even when nearly all monitors were 4:3, AR scaling was necessary. It's just that you could hard-code 4:3 and not have to worry.
Marc Bernier
@jheriko, it's been a while since I looked at the Windows API for this, but I could have sworn that there were both horizontal and vertical DPI properties. Combined with screen height and width, you should be able to calculate AR, no?
Marc Bernier
you would think so, but these don't do what they say on the tin unfortunately - although its getting better since MS has been pushing its high DPI stuff from Vista onwards, i've seen "96 dpi" at all kinds of scales and ARs. :P
jheriko
A: 

You can do this using GDI+, and transforms. For details on using Matrix to do transforms, see this article on CodeProject.

That being said, this is much, much simpler using WPF's drawing options. In addition to being a retained mode model, which is much simpler when doing simple graphics (ie: move an object instead of constantly redrawing), it has some other nice benefits. The main benefit is that everything in WPF is done using floating point values, and is completely scalable, with no extra real effort. For details on this, see Shapes and Basic Drawing with WPF, which includes both drawing and transforming of shapes.

Reed Copsey