2013-02-08 1 views
0

먼저 이것이 Content.RootDirectory = "Content"가 아니라고 말하고 싶습니다. 문제. 이 코드 줄을 사용하거나 사용하지 않고이 작업을 시도했습니다. 세 개의 사전이있는 FileFactory 클래스가 있습니다. 하나는 텍스처 용이고 다른 하나는 사운드 용이고 다른 하나는 스프라이트 글꼴 용입니다. 나는 또한 다른 유형의 객체에 대해 XML 파일로로드하는 다른 팩토리를 가지고 있으며 완벽하게 작동합니다. 여기에 글꼴을로드하는 코드는 다음과 같습니다XNA ContentLoadException 파일이 명확하게 존재할 때 Directory.GetFiles에 의해 주어진 배열에서

 public static void LoadFonts(ContentManager content) 
    { 
     string[] filePaths = Directory.GetFiles(@"Content\fonts\"); 
     string key; 

     foreach (string s in filePaths) 
     { 
      key = Path.GetFileNameWithoutExtension(s); 
      Fonts.Add(key, content.Load<SpriteFont>(s)); 
     } 
    } 

가 제공 오류 : "오류로드"내용 \ 글꼴은 \ ammoFont.xnb은. "파일을 찾을 수 없습니다." 비록 그 파일이 분명히 거기에 있다고하더라도 그것이 filePaths 배열에 문자열로 추가되는 디렉토리에 있어야만한다는 것을 고려하면. 나는 폴더를 확인해도 거기에있다. 여기에 전체 오류는 다음과 같습니다

Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
Message=Error loading "Content\fonts\ammoFont.xnb". File not found.
Source=Microsoft.Xna.Framework StackTrace: at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName) at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String assetName, Action`1 recordDisposableObject) at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) at OfUnknownOrigin.FileFactory.LoadFonts(ContentManager content) in C:\Users\Chris\Documents\Visual Studio 2010\Projects\WindowsGame1\WindowsGame1\WindowsGame1\FileFactory.cs:line 38 at WindowsGame1.UnknownOrigin.LoadContent() in C:\Users\Chris\Documents\Visual Studio 2010\Projects\WindowsGame1\WindowsGame1\WindowsGame1\Game.cs:line 110 at Microsoft.Xna.Framework.Game.Initialize() at WindowsGame1.UnknownOrigin.Initialize() in C:\Users\Chris\Documents\Visual Studio 2010\Projects\WindowsGame1\WindowsGame1\WindowsGame1\Game.cs:line 102 at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun) at Microsoft.Xna.Framework.Game.Run() at WindowsGame1.Program.Main(String[] args) in C:\Users\Chris\Documents\Visual Studio 2010\Projects\WindowsGame1\WindowsGame1\WindowsGame1\Program.cs:line 15 InnerException: System.IO.FileNotFoundException Message=Error loading "Content\Content\fonts\ammoFont.xnb.xnb". File not found. Source=Microsoft.Xna.Framework StackTrace: at Microsoft.Xna.Framework.TitleContainer.OpenStream(String name) at Microsoft.Xna.Framework.Content.ContentManager.OpenStream(String assetName) InnerException:

답변 : 이것에

Fonts.Add(key, content.Load<SpriteFont>(s)); 

:이 코드 변경

Fonts.Add(key, content.Load<SpriteFont>("fonts\\" + key)); 
+0

'LoadFonts()'메소드 밖에서'Content.Load ("fonts/ammoFont");가 단독으로 작동합니까? –

+0

예, 작동하지 않습니다. 이것이 FileFactory 클래스를 만들기 전에 내가했던 일입니다. – Bagofsheep

답변

0

예외 메시지에서와 같이 호출하는 문자열이 잘못 나온 것처럼 보입니다. 내용은 두 번 거기에, 그리고 확장은 두 번있다 :

Error loading "Content\Content\fonts\ammoFont.xnb.xnb" 

당신은 당신이 배열을 초기화 코드를 게시,하지만 당신은 정의에이를 경우, 제거 didnt한다.

+0

다음은 초기화 될 글꼴 사전입니다. public static Dictionary Fonts = new Dictionary (); ' 콘텐츠와 확장 프로그램이 두 번 왜 있는지 알 수 없습니다. – Bagofsheep

+0

'Fonts.Add (key, content.Load ("fonts \\"+ key)); ' –

+0

시도해 본 것 같습니다. 왜 그래야하는지 모르겠습니다. 고맙습니다! – Bagofsheep

0

게임 콘텐츠 경로는 당신의 Content.RootFolder ("내용에 상대적이어야합니다 \ ") 파일 확장명을 포함해서는 안됩니다 (확장자가 다른 경우에도 파일 이름이 중복되지 않도록하십시오).

+0

경로는 그 경로와 관련이 있습니다. 나는 Content.RootFolder를 설정하거나 설정하지 않고이 작업을 시도했으며 같은 일이 발생한다. Directory.GetFiles의 경로는 Content.RootFolder와 관련이 없습니다. 나는 아무 소용이없는 코드와 문자열 레이아웃을 보충했다. – Bagofsheep

+0

경로에 파일 확장명을 포함 시키려면 해당 확장명을 제거해야합니다. – user1306322

+0

위의 코드를 살펴보십시오. 경로에 파일 확장자를 추가하지 않았습니다. – Bagofsheep