我目前正嘗試移植一款我從XNA開始使用Monogame的遊戲,但我在獲得內容管道合作方面遇到了一些麻煩。我的遊戲使用許多XML文件作爲XNB資產來表示遊戲中的對象,我按照here的說明創建了這些對象。然而,嘗試這種跨字對字移動到Monogame產生以下錯誤:通過Monogame內容管道加載XML文件?
An unhandled exception of type 'Microsoft.Xna.Framework.Content.ContentLoadException' occurred in MonoGame.Framework.dll
Additional information: Could not load Parts\Window.xnb asset as a non-content file!
這是我一直在使用來定義XML文件的內容類:
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace FileTypes
{
public class PartFile
{
public struct State
{
public Rectangle[] frames;
public int[] collision;
}
public Vector2 size;
public string image;
public string defaultState = "default";
public bool fillBG;
public int ticksPerFrame;
public Dictionary<string, State> states;
public string[] modules;
}
}
下面是該項目的XML文件中的一個:
<?xml version="1.0" encoding="utf-8" ?>
<XnaContent>
<Asset Type="FileTypes.PartFile">
<size>2 3</size>
<image>Computer</image>
<defaultState>default</defaultState>
<fillBG>false</fillBG>
<ticksPerFrame>7</ticksPerFrame>
<states>
<Item>
<Key>default</Key>
<Value>
<frames>
0 0 40 60
40 0 40 60
</frames>
<collision>
0 0
0 0
0 0
</collision>
</Value>
</Item>
<Item>
<Key>active</Key>
<Value>
<frames>
80 0 40 60
120 0 40 60
</frames>
<collision>
0 0
0 0
0 0
</collision>
</Value>
</Item>
</states>
<modules>
<Item>testModule</Item>
</modules>
</Asset>
</XnaContent>
最後這裏是代碼的示例中,我用它來加載文件:
FileTypes.PartFile srcPart = content.Load<FileTypes.PartFile>("Parts\\" + name);
有人知道我需要做什麼才能讓我的代碼在Monogame中工作嗎?我一直在網上瀏覽一段時間,但到目前爲止,我還沒有找到解決我的問題的方法。另外,如果我一直在討論整個系統的錯誤,並且處理我想要做的事情有一個更簡單的方法,我很樂意聽到它。
在此先感謝!
我已經做到了這一點,但它仍然無法正常工作。 –
oops,只是看看你發佈的鏈接(我從來沒有使用xml的內容管道數據),我懷疑你可以在monogame中做到這一點,因爲它沒有內容管道,所以它不能將xml轉換爲xnb文件,您最好在xna中構建文件,然後將xnb文件複製到您的monogame項目中,然後對其執行上述^操作 – Nico