views:

146

answers:

4

I am making a small game as sort of a test project, nothing major. I just started and am working on the graphics piece, but I'm not sure the best way to draw the graphics to the screen.

It is going to be sort of like the old Zelda, so pretty simple using bitmaps and such. I started thinking that I could just paint to a Picture Box control using Drawing.Graphics with the Handle from the control, but this seems cumbersome. I'm also not sure if I can use double buffering with this method either.

I looked at XNA, but for now I wanted to use a simple method to display everything.

So, my question. Using the current C# windows controls and framework, what is the best approach to displaying game graphics (i.e. Picture Box, build a custom control, etc.)

EDIT: I will add how I am currently drawing to the picture box. I have a Tile object that just contains the pixels for the tile ( List< List< Color>> texture; ), nothing more for simplicity. I then draw that to the pic box by iterating through the pixels and using the FillRectangle method using a brush with the current pixel color and the size specified by a scale variable:

int scale = 5;
for (int i = 0; i < texture.Width;)
{
    for (int j = 0; j < texture.Height; ++j)
    {
        int x = i * scale;
        int y = j * scale;
        picBox.FillRectangle(new SolidBrush(currentPixelColor), new Rectangle(x, y, scale, scale));
    }
}

Yah, pretty cumbersome. Any suggestions or comments are appreciated.

A: 

See this answer for a sample application (source code included) that will get you started.

MusiGenesis
A: 

I honestly believe XNA is by far one of the simplest game design frameworks I've used. Aside from that you could utilize WPF to draw objects on screen.

Adam Driscoll
A: 

First I strongly recommend using XNA or DirectX for game development...

However, if you do not want XNA nor DirectX help.... then you will be forced to use .Net GDI+ painting tools.....

By this way, you can draw points, lines, circles, rectangles, arcs, bitmaps, texts and many more by GDI+ (that all is -of course- available in C# and .Net...)

You may make a new simple control (or use an existing one such as image box or the form itself !), then you will have to override its OnPaint(PaintEventArgs e) function... Then you will use e.Graphics to draw whatever you want...


Example:
Simple Tetris Game Tutorial in C#


EDIT:
Using a GDI+ to draw pixel by pixel picture is quite a performance drop!!


Better is to draw shapes yourself (circles,.. etc)

Betamoo
+2  A: 

I would recommend, that you take another look at XNA and try a few samples. It is really simple to make simple games with XNA as long as you stick with 2D. The framework does an excellent job at wrapping all the details in a easy to understand flow, where you basically fill in the blanks so to speak.

I did a complete (but very simple) Xbox game for my son in just 8 hours without little previous experience.

If you move to 3D things become more complex, as you have to understand various view models, shaders and so forth, but for 2D it is really simple to get started.

Another advantage of 2D is that the required tools are easier to get. I did all the graphics using Photoshop, the sounds were MP3s and voices I recorded using the Windows recorder. For 3D you need complex tools for building and exporting models and so forth.

Brian Rasmussen
I did think about the fact that I could pop the game on the XBox, which would be awesome, but I wanted to go cross platform if I wanted, too. Can XNA be cross platform, or would I have to recode my project for another platform?
Mike Webb
Not unless you count Windows, Xbox, Zune and the upcoming Windows Phone as cross platform. However, because of the somewhat restricted setup the developer experience is really good. You use Visual Studio and to develop and debug games running on the console. It is really smooth imo. Only drawback is the $100 license to be able to deploy to the Xbox. If you just want to do Windows games there's no license.
Brian Rasmussen
Is there a pretty good comprehensive tutorial or help site for learning XNA?
Mike Webb
Slightly off-topic, but is it possible to deploy a C# WinForms app to the Xbox?
MusiGenesis
There are lots of useful tutorials on the XNA Creators Club site http://creators.xna.com/en-US/. I also picked up a couple of books but none of them were really good imo.
Brian Rasmussen
@MusiGenesis: WinForms is not supported on the Xbox. See http://msdn.microsoft.com/en-us/library/bb198211(XNAGameStudio.10).aspx
Brian Rasmussen
@Brian: thanks for the link. I got all excited when I saw that xbox supports a subset of the compact framework, but then I saw that it doesn't even support `System.Drawing`. Oh well.
MusiGenesis
Wound up looking into XNA again. Pretty simple stuff. Looks like I'll be using it. Thanks for the suggestions and comments all of you.
Mike Webb