# WPF or WinForms for Game Development and learning resources? [closed]

I'm looking to create a game framework for my own personal use... I want to use WPF, but I'm unsure if that is a wise choice...

The games I will be writing should not require high performance graphics, so I am hoping to build on native classes... I do not want to rely on external DLL's unless I generate them myself.

The games will be for young children, say 4 to 8. Most will be learning puzzles or simple shooters.

The most advanced will be a platform game (non-scrolling screen like the old Atari Miner 2049er game).

I think I know how to write something like the old Atari Chopper Command (partially written and my 4 year old loves it, but I used WinForms and GDI), Pac-Man, Tetris, Astroids, Space Invaders, Slider Puzzle, but I do not really know how to write the platform game... In my mind, I'm getting caught in collision detection and how to make a character jump and how to make a character walk up a slope or steps...

Can anyone point me to information on developing a platform game in C#?

Would you suggest WinForms or WPF for game development?

I'm not looking for great graphics and speed, just entertaining game play...

• "This vs that" questions aren't really useful (see this post: blog.stackoverflow.com/2011/08/gorilla-vs-shark). Your main question seems to be about how to develop a platformer in C#. Neither WinForms nor WPF are very good for this. Look at XNA, MonoGame, SlimDX, OpenTK, or C# bindings for libraries like SDL or SFML. – michael.bartnett Sep 25 '12 at 15:32
• You're asking for a discussion. There's no correct answer here. See the FAQ about what types of questions to ask here. – MichaelHouse Sep 25 '12 at 16:28
• I mainly meant to ask about the platformer... but I rambled - sorry. – Stephen Lee Parker Sep 29 '12 at 4:52

"I'm getting caught in collision detection and how to make a character jump and how to make a character walk up a slope or steps..."

Why do you want to write it yourself? You could (if you want simple 2d graphics) use an existing framework for platformers and save a lot of time and energy.

How to make characters walk up and down a slope or a stairway entirely depends on how you model this slope and or stairway in the code. :) It also depends on the kinds of physics you would like to involve, is the steep slope, slippery? I think these questions could all find answer, however it would be simpler to ask them one at a time and have some base code to start with.

I will start by answering the question about collision detection. This is implemented in a lot of existing frameworks. If you are using a 2d-array to represent a tilemap, you can handle collision between the character and the wall this way: Assuming the character starts in a collision free area and her feet are positioned in (x,y), you check which tile that is:

tilePos.x = character.x / TILE_WIDTH;
tilePos.y = character.y / TILE_HEIGHT;


If the character is less wide than one tile and is positioned around the center of the current tile, you simply check if there is a tile directly underneath it.

//Tile exists is a function that looks at the 2d-array that represents the tile map
//and checks if a floor tile exists in (int x, int y)
onGround = tileExists(tilePos.x, tilePos.y - 1);
//if the character is not positioned in the center of the tile, you'd have to check
//tileExists(tilePos.x +/- 1, tilePos.y - 1); depending on where it is leaning to.
//This is also true if the character is too wide to stand on a single tile.


if there is no tile, the character begins to fall..

character.speed.y -= GRAVITY; //a constant you could define

//Checking if a character can move left or right is just the same
movementDirection = 1 * isRightKeyPressed() - 1 * isLeftKeyPressed();
//Assuming the character is two tiles high
canMove = !tileExists(tilePos.x + movementDirection, tilePos.y) && !tileExists(tilePos.x + movementDirection, tilePos.y + 1);


if(isUpKeyPressed() && onGround) character.speed.y += jumpSpeed();


This is psuedo code and it needs some refining.. It should give you an idea.

If you never made a platformer, I suggest you learn about states too.

• THANK YOU - exactly what I needed! As for the framework, it is part of the learning experience, and I want to make sure it works at almost any hardware I throw at it... I wrote a simple shooter for my son using XNA only to find out XNA will not work on the hardware he is allowed to use. – Stephen Lee Parker Sep 29 '12 at 4:24

I would reiterate that neither WinForms nor WPF would be good, even for simple games. XNA is specifically made for this scenario.

WinForms has an immediate graphics mode so you will have to refresh and repaint the window every "frame." The trouble is that GDI painting isn't great for performance and you have to play games with double buffering to prevent flickering.

WPF uses retained graphics, which is somewhat easier on you. You can create all your shapes and images, give them to WPF and update them when need be. WPF will automatically redraw what needs redrawn and properly sort everything for you. It also has the benefit of hardware acceleration in some cases. You could potentially do some crazy stuff in WPF to achieve some fancy effects (tranformations, shaders, etc.). But while its great that WPF has this power, it is not meant for real-time graphics.

XNA is built using C# and is designed to be easily understood. The starter-project provided with the install gets a game window up and running with a SpriteBatch ready to go. You can get 2D sprites drawing in no time. There is some learning curve with the content pipeline, since it is part of the build procedure. Like most graphics frameworks, it is an immediate renderer, so every frame you have to tell XNA what sprites to draw and where to put them. XNA also abstracts out other parts of game development to make your life easier: audio, input (mouse/keyboard/gamepad), content management, etc.

• can't use XNA with my hardware - reason for post in the first place... – Stephen Lee Parker Sep 29 '12 at 4:16

Seems like a bit of a loaded question. I would use neither as they are both for windows applications, not particularly good for writing games. Have you looked into the XNA framework? It uses c# which you seem to want to use, but is actually meant for writing games.

• Used XNA on my developent system to write a game for my son only to find out XNA would not work on the hardware he is allowed to use... – Stephen Lee Parker Sep 29 '12 at 4:22

Writing games with a WinForms or WPF UI is perfectly fine. There are thousands upon thousands of popular and enjoyable games that don't need or benefit from hardware support. Just think, if nothing else, of the classic Windows games Minesweeper, Solitaire, or Freecell. I could easily imagine those games being implemented today with Forms or WPF. In fact, being the casual games that they are, that might be even the preferred way to go for me.

That being said, it's important to pick the right tools for the job. Since you mentioned Jump & Run mechanics and collision detection, then you probably could cook something up in WPF, creating your own game loop and drawing and whatnot, working with UI components instead of your own specialized classes.

However, is that the smart thing to do when there is XNA? Definitely not, as specialized game development frameworks ease your work so much when creating games with somewhat higher technical or design demands.

So as a conclusion, you should really learn how to use a game development framework as your design goals become more complex, and if C# is what you know, XNA would be the most obvious answer as to which you should be using.

• can't use XNA with my hardware - reason for post in the first place... Since making this post, I've created tests for both WinForms and WPF. Both seem to work well, getting over 50fps with 200 moving objects and a bit of AI for the objects. I still have not decided wich is best - I may end up picking WPF simply because I have only written a few apps in WPF - a learning experience... – Stephen Lee Parker Sep 29 '12 at 4:20