XNA Programming First Impressions

Currently I am working on a 2D Platformer which has yet to be given a title with 2 programmers, 2 artists, and a sound guy. I have the role of the lead programmer, and until now have had no experience programming a video games. I decided to use XNA because I am proficient with the .net framework and C#, and I am very happy with how simple Microsoft makes development of complex software. With that said, I am very happy with XNA so far from what I can tell, XNA makes developing a video game easy to understand and build.

Early on in my development career I used the MSDN video tutorials on C# and the .Net framework to get acquainted with the Microsoft way of doing things. Those tutorials sped me through so much content so quickly I was able to find a .Net programming job before entering my junior year of college. The videos were just enough to tell me what existed in the .Net framework and how to call up the information if I needed it in future development projects. In the case of resources for XNA I am a little disappointed. I first watched many of the videos on http://creators.xna.com/en-US/ which helped get started with XNA programming but I did not feel that they were as comprehensive in regards to what was available to a beginning developer. With that in mind I decided to read through all of the documentation relevant to my project on http://msdn.microsoft.com/en-us/library/bb200104.aspx this was a great help and I recommend reading through everything here, it may be tedious to do so, but when starting a new project it will help you get past some of the initial headaches, especially from the standpoint of being new to game development.

For our game I set out to modify the Platformer template project that comes with XNA studio. I found 2 tutorials, one on adding a horizontal parallax effect (horizontal side scrolling), and the other on adding a power up. They were the tutorials were fairly simple and let me familiarize myself with the content pipeline. Both tutorials worked as stated and were uneventful as far as confusion goes.

I then realized that I would love to add a vertical parallax effect, which I felt would be fairly simple. I typically don’t like to assume things when exploring new ground, but there was one thing that I felt to be so simple that there is no way I could be wrong. I even read (and glazed over) it in the MSDN documentation. My fatal assumption came from my school experience, in every math class I have ever taken the (0,0) point on an x,y plane has always been oriented toward the bottom left. X was zero at the left and increased moving right, and Y was zero at the bottom and increased moving up. In the XNA framework (as illustrated in the picture) the X position remains intact with my assumption, but the Y starts at the top and increases moving down. The horizontal parallax effect was created exactly how I would expect it to. In my attempt to make the effect vertical as well proved to be a headache that consumed much more time then I would have liked. Since frames are drawn using a vector to decide their position my initial calculations would make the effect happen in the opposite direction entirely. The solution of course is to do all the calculations for the parallax effect making sure to orient yourself with the (strange and unintuitive) XNA coordinate system ( I really hope that saves someone some time when getting started.)

Now the parallax effect works so well, that I can tile addition backgrounds upward and make the character use platforms to get into space!

Please post comments with any questions or if you would like to see a code sample.

2 comments:

  1. "strange and unintuitive"? nice one :) to me, on the other hand, having 0, 0 point in upper left always felt completely natural, probably because of the MS-DOS and BASIC times (and, in fact, all the console app programming), where all print statements start right there, and 0,0 char is always in upper left.

    ReplyDelete
  2. As someone who just decided out of the blue to start making games, for some reason 0, 0 threw me. I really think the reason is while in school any type of graphing was done with 0, 0 at the bottom left :) Interesting to find out what haunts you from those times lol.

    ReplyDelete