开发者

Best direction for displaying game graphics in C# App

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 meth开发者_JAVA百科od 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.


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.


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.


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜