2

XNA ゲームを作成しています。XML ファイルですべてのレベルの詳細を指定できるようにしました。XML ファイルは、デシリアライズされ、レベルの詳細を設定するために使用されます。

現時点では、コンピューター上のファイルを参照しているだけです - 私の質問は、これをより一般的に参照するにはどうすればよいですか?

コンテンツ フォルダーに xml を追加すると、スキーマなどに関する多数の苦情が発生したため、それはおそらく正しいルートではないと思いました。

助言がありますか?

XNA からすべてのエントリを削除しようとしましたが、次のようになります。

メソッドにアクセスしようとして失敗しました: System.IO.StreamReader..ctor(System.String)

編集:

xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
  <Asset Type = "RDrop.Level[]">
  <Item>
    (stuff)
  </Item>
  <Item>
    (stuff)   
  </Item>
  </Asset>
</XnaContent>

編集:

新しい Windows Phone プロジェクトを開始しました。以前のプロジェクトはそうではありませんでした。すべてをコピーして、このチュートリアルで「dataTypes」を追加しました。

http://msdn.microsoft.com/en-us/library/ff604979.aspx

ゲーム プロジェクトの参照 -> コンテンツ、MyDataTypes。コンテンツ参照 -> MyDataTypes。

XML は以前の編集のままで、[追加] -> [既存のアイテム] -> [Level.XML] を介してコンテンツ フォルダーに含まれています。

何か案は?

4

2 に答える 2

2

You can leave the build action as "Compile". One method to do what you want is the following:

Create a class that the xml is going to be describing. Example: Level.cs

Then structure your xml file like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
    <Asset Type="The_Level_class_namespace.Level">
        <Property1>Value</Property1>
        <Property2>Value</Property2>
        <Property3>Value</Property3>
        <Property4>Value</Property4>
    </Asset>
</XnaContent>

if you want the xml to describe an array of objects you can do structure the xml like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XnaContent>
    <Asset Type="The_Level_class_namespace.Level[]">
        <Item>
            <Property1>Value</Property1>
            <Property2>Value</Property2>
            <Property3>Value</Property3>
            <Property4>Value</Property4>
        </Item>
    </Asset>
</XnaContent>

From there you just need to make sure your values are in the proper format. For example a vector2 object would be like this:

<Vector2Property>x_value y_value</Vector2Property>

Make sure that your content project references the game project or library project.

Hope this helps :)

于 2012-09-18T21:21:14.933 に答える
0

XML ドキュメントのプロパティを開きます (コンテンツ フォルダを右クリックします)。Build Action を : None に設定できます。

そうすれば、コンパイラはスキーマを分析しないため、警告は生成されません。

(これについては完全にはわかりません、私の最初の推測です)

于 2012-09-18T19:50:28.423 に答える