Posts Tagged ‘content pipeline’

First Run on Xbox 360 : Problems and Solutions

Friday, April 2nd, 2010

I decided about a month ago to start working on the Xbox 360 version of Spring Up in April. I think it can be interesting to share my experience about that.

Part 1 : XNA Creator Membership

Basically, you just need to pay creator membership (99 € for one year in Europe), launch XNA Game Studio Connect on your console and that’s it.

Problem 1 : You have problems to redeem your XNA account to a new X360 profile?

Solution 1 : Do not mix up your forum name and GamerTag. Yes, this one was easy but it took me at least 30 minutes to find out what was happening. :)

Problem 2 : XNA Game Studio Connect does not recognize your account as premium when you launch it even though you paid for membership?

Solution 2 : You have to wait for some time (a few hours, maybe half a day) and everything will be fine. Quite frustrating, I know.

Part 2 : Compiling your game for Xbox 360

Microsoft made something simple : just right click on your project in Visual C# and choose “Create copy of Project for Xbox 360″. I took my main project and all the dependencies were converted too.

Problem 3 : You have very strange compiling errors? When converting Box2D.XNA, I had weird errors such as “Class C does not implement inherited abstract member M” AND “no suitable method found to override M”.

Solution 3 : Make sure you use the proper version of assemblies. I don’t know why but the converter put assemblies of XNA 3.0 instead of 3.1. Using 3.1 assemblies fixed my problem.

Problem 4 : The code does not compile but it works fine on Windows?

Solution 4 : Make sure you do not use windows specific code. You will be able to see warning icons if you have invalid assemblies in your Xbox 360 projects. If you want to keep windows specific code, just use #if WINDOWS / #endif so that it compiles properly on Xbox 360. In my case, my level and dialog box editors are only available on windows because it needs to create XML files.

Problem 5 : You can’t build your XNB data from XML using your own classes?

Solution 5 : Make sure the Content projects still have references to windows builds. Resources are built on the development computer, using the windows assemblies.

Part 3 : Running the Game on Xbox 360

Problem 6 : Code 3 Error?

Solution 6 : When you have Code X errors, it is because the console hangs without being able to break or throw an exception to the debugger. To track this problem, I simply traced the code I suspected. As the problem happened on a specific action, I could easily see where was the problem. My problem was just a null pointer access that happens only when there is no savegame. I always have a savegame on PC, so I did not see the problem before. The strange fact is that when I traced the code the second time, I properly had the NullPointerException.

Problem 7 : Your game is slow?

Solution 7 : I knew Xbox 360’s are usually slower than PCx with XNA but I was still very surprised my I ran my game for the first time. I immediatly launched a release build to try to reassure myselft but it’s still quite slow. I am not sure what is the problem for now so I will improve my profiling code to see which GameComponent is the problem.

Conclusion

That’s it for my first run on X360. I hoped this helped some of you!

Win/Mac and X360 differences (3) : XNA Content Pipeline

Wednesday, January 13th, 2010

In this post, I’ll talk about the XNA Content Pipeline. When I first tried to load a resource in the XNA game, I was trying to do as usual : opening a file and reading it using standard file reading functions. However, on XNA you have to use the Content Pipeline provided and to be honest, they have made a very good work with that. This pipeline can load some known file formats (jpg textures or wav sounds for instance) but you can extend the pipeline for your own custom formats.

I used many different types of file format for Spring Up!, for instance:

  • TGA for 32b images (I used TGA because it’s a very simple file format)
  • SWF for menus, level description and physics definition (ShockWave Flash, using the gameswf library)
  • WAV for sounds
  • OGG for music
  • Custom text files for translated texts and particle definition (called RSC and PRT)
  • Custom binary files for various data (DAT files).

The XNA Content Pipeline is really integrated into your XNA game project. You just add the resource to your project and when you compile it, the data is imported and converted in a XNB (XNA Binary File) using a Content Importer. This XNB file is generated for the right platform. It means you do not have to bother about little/big endian of the platform (Windows or X360). Once the resource is in your project, you create game objects with only one line of code. For instance, you can add a texture file to your project, and then load it using the following code:

Texture2D my_texture = Content.Load<Texture2D>("texture");

There are many file formats handled by XNA but when using specific data, you have to develop your own custom Content Importer. As told in a previous article, I will not port gameswf for many reasons so all the data I have in SWF files has to be included in another way into the X360 game. I started to include one of the most important data : the definitions of the levels. To do this on X360, I developed a quick XML exporter in the PC version of Spring Up! Then, I read the XML with my custom Content Importer. The XNA Game Studio then generates the XNB. The following diagram shows the flow of the data:

Data flow for levels data in Spring Up!
Levels data flow in Spring Up!

Now that my importer is in place, I can read a level definition using the following code:

LevelDef level = Content.Load<LevelDef>("level01");

And that’s it!

I have three importers already in place in the current version:

  • Sprite : binary format containing position and size of a sprite in a texture page. It was my first importer using XNA. It could (should?) have been XML. Original PC data was in the SWF, it is exported in binary from the PC game.
  • Level : position and type of items of the levels of the game. Original PC data was in the SWF, it is exported in xml from the PC game.
  • Physics : the definition of the physics properties of the items (size, shape, mass). This one is not completed yet, I still have pivots and joints to include. Original PC data was in the SWF (in actionscript code), it is exported in XML from the PC game, too.

If I knew from the beginning that the game would be developed on XNA, I would have done differently. The fact that I’m porting an existing product made me choose this solution of creating the exporters on PC and reimporting the data in XNA Game Studio. Ideally; I would have createed a level editor (with a Windows XNA project probably) saving data in XML. Then I’d use the content importer to put the resource in the XNA game and read directly the XML for a PC/Mac game (see diagram below).

Possibility for a multiplatform project
Possibility for a multi-platform PC/Mac/X360 project

As I plan to improve greatly the game, it is still possible that I will develop a specific level editor to be able to create new types of objects and physics items.

That’s it for my basic introduction to the XNA Content Pipeline. If you have any questions about the use of the pipeline, about importers or anything else, feel free to ask in the comments section below!