XNA: ContentPipeline content pipeline in Win8 Metro App

Source: Internet
Author: User
Starting

This article does not actually solve the ContentPipeline (Content pipeline) Problem of XNA in Win8, but describes how to use a specific ContentPipeline (Content pipeline) and read Content in XNA through Content. load <T> Read, the method to obtain resources is encapsulated well, so that no file suffix is required, because XNA compiles all resources into xnb resource files through the content pipeline, XNA comes with some default resource types. In any XNA project, the resource opening attribute in the Content sub-project, such:

The input and output correspond to a processor, that is, there is an input and an output, and the input and output of the content are also relatively simple, such as Texture and Model, these can be found in the official documentation relatively clear examples, but sometimes, we need not only these standard resources, but more custom resources, such as in the cocos2d-xna. plist files. The standard types you specified for these files are useless. Even if there is no error during xnb compilation, it will crash during Load. How can this problem be solved?

In the previous article, some friends suggested using FromStream to solve the problem. I was very excited to try it, but this method is not universal, you must know that the most famous thing in xna is custom resources. The custom xnb will be a big project through stream parsing, and even if the correct resources can be output, but the conversion code is equal to the total amount of your resources.

Custom content Pipeline

Since there are no standards, you can only customize them. XNA provides ContentImporter and ContentProcessor to create custom resources, and even provides related templates in Studio:

Then write the processing class of the input and output you want to process:

The specific code is actually very simple, it is recommended to refer to this section of the cocos2d-xna processing, from the project.

Then select your resource and change it. In one of my games, "A Xiang Hurdle", there is a custom data file, this data file is mainly used to describe the location information of the animation frame of the role. Obviously, I need to convert it myself to obtain its data stream:

After obtaining the data stream, you are doing special processing, in the cocos2d-xna if you encounter. plist files need the same way to make your demo run normally, this can be referred to the coco2d-xna official test can understand.

In MonoGame XNA

Now we are converting to Windows 8. What should we do when we use MonoGame to retrieve custom resources? After all, there is no compilation method, which has plagued me for a long time. When I figured it out, I found it was so simple. Since I had no input, I didn't need to worry about the input, you only need to read xnb, so you can directly reference the Content index. For example, if your custom Content output is CCContent, you can directly use Content. load <CCContent>, so the Code does not need to be modified in this way. Of course, the practice is as simple as that. The compiled xnb file is only in the project's Content directory, and the property is set to Content. It is expected that Microsoft will be able to output XNA For VS2012 as soon as possible, so that this is not necessary during development.

I thought I could write a lot. I found that there is nothing to write now. As long as I know a method, other problems will naturally be solved. In order to make this article more full, the following is a video of the WP and Win8 editions of "A Xiang Hurdle:

The custom content pipeline used in this project will be attached with the source code by Convention. Unfortunately, this time is not enough. Please forgive me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.