2013-08-31 5 views
0

저는 Windows Phone 게임을 만들고 있어요. 저는 XNA에서 초보자입니다. 내 문제는 내 메인 파일에있는 Content.RootDirectory = "Content";입니다. 디버깅을 시작할 때 내 하위 클래스 파일에 다른 파일을 넣을 때 콘텐츠에있는 로고를 찾을 수 없다는 메시지가 표시됩니다.하위 클래스의 텍스처 불러 오기

Content_logo.RootDirectory = "Content";

Logo_Texture2d = Content_logo.Load<Texture2D>("Logo"); 

나는 오류가 내용이 ContentManager에로드 된 후이 속성이 변경 될 수 없다는 표시됩니다 다른 루트 디렉토리를 제작하려고합니다. 내 질문에 어떻게 하위 클래스에서 콘텐츠 디렉터리에서 내 텍스처를로드 할 수 있습니다.

public class MainFile : Microsoft.Xna.Framework.Game 
{ 
    GraphicsDeviceManager graphics; 
    SpriteBatch spriteBatch; 
    ScreenStates screentState; 

    Rectangle TouchS_Y_X; 

    Logo logo; 
    Menu0 menu; 
    Choose_Pets choose_pets; 
    ScreenStates.CurrentGameState GameState; 

    public MainFile() 
    { 
     graphics = new GraphicsDeviceManager(this); 

     Content.RootDirectory = "Content"; 

     // Frame rate is 30 fps by default for Windows Phone. 
     TargetElapsedTime = TimeSpan.FromTicks(333333); 

     // Extend battery life under lock. 
     InactiveSleepTime = TimeSpan.FromSeconds(1); 

     this.screentState = new ScreenStates(); 
     ///choose_pets = new Choose_Pets(); 
     choose_pets = new Choose_Pets(); 

     logo = new Logo(); 

     menu = new Menu0(); 
    } 


    protected override void Initialize() 
    { 
     // TODO: Add your initialization logic here 
     GameState = ScreenStates.CurrentGameState.Logo; 
     base.Initialize(); 

    } 


    protected override void LoadContent() 
    { 
     TouchS_Y_X = new Rectangle(0, 0, 1, 1); 
     // Create a new SpriteBatch, which can be used to draw textures. 
     spriteBatch = new SpriteBatch(GraphicsDevice); 

     this.menu.Load_Menu(GraphicsDevice, Content); 
     choose_pets.Load_ChoosePet(Content, GraphicsDevice); 

     // TODO: use this.Content to load your game content here 
     base.LoadContent(); 
    } 


    protected override void UnloadContent() 
    { 
     // TODO: Unload any non ContentManager content here 
     //this.logo.Unload_logo(Content); 
    } 


    protected override void Update(GameTime gameTime) 
    { 
     // Allows the game to exit 
     if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) 
      this.Exit(); 

     #region Games States 

     switch (GameState) 
     { 
      case ScreenStates.CurrentGameState.Logo: 

        logo.Update_logo(gameTime); 

        this.logo.Load(this.Content, this.GraphicsDevice); 

        if (logo.FadeOut_logo == true) 
        GameState = ScreenStates.CurrentGameState.Menu; 

        break; 

      case ScreenStates.CurrentGameState.Menu: 
        menu.Update_Menu(gameTime); 

       break; 

      case ScreenStates.CurrentGameState.CharactersChooser: 
        //choose_pets.Update_petchoose(gameTime); 
       break; 
     } 
     #endregion 

     // TODO: Add your update logic here 
     base.Update(gameTime); 
    } 


    protected override void Draw(GameTime gameTime) 
    { 
     GraphicsDevice.Clear(Color.Black); 

     #region GameStateDraw 
     spriteBatch.Begin(); 

     switch(GameState) 
     { 
      case ScreenStates.CurrentGameState.Logo:   
       logo.Draw(spriteBatch); 
      break; 

       //Menu Draw State 
      case ScreenStates.CurrentGameState.Menu: 
      menu.Draw_Menu(spriteBatch); 
      break; 

      case ScreenStates.CurrentGameState.CharactersChooser: 
       // choose_pets.Draw_petChoose(spriteBatch); 
      break; 
     } 
     spriteBatch.End(); 
#endregion 

     base.Draw(gameTime); 
    } 
} 
} 

그리고 이것은 내 첫 번째 열거가 화면에 표시 될 것입니다 내 서브 클래스 로고입니다 ..

class Logo 
{ 
    Texture2D Logo_Texture2d; 
    Rectangle Logo_Rec; 
    Color Logo_color; 

    public bool FadeOut_logo = false; 

    public double _Timer_logo; 

    SpriteFont Norm_fonts; 

    public void Load(ContentManager Content_logo, GraphicsDevice graphics_logo) 
    { 
     Logo_Texture2d = Content_logo.Load<Texture2D>("Logo"); 
     Logo_Rec = new Rectangle(0, 0, graphics_logo.Viewport.Width, graphics_logo.Viewport.Height); 

     Norm_fonts = Content_logo.Load<SpriteFont>("Fonts\\Normal_Font"); 
    } 

    //public void Unload_logo(ContentManager Content_logo) 
    // { 
     // if (FadeOut_logo == true) 
     //  Content_logo.Unload(); 
    //} 

    public void Update_logo(GameTime gametime_logo) 
    { 

     _Timer_logo += gametime_logo.ElapsedGameTime.TotalSeconds; 

     if (gametime_logo.ElapsedGameTime.TotalSeconds >= 10) 
      Logo_color.A--; Logo_color.B--; Logo_color.G--; Logo_color.R--; 

     if (Logo_color.B == 0) 
      FadeOut_logo = true; 

    } 

    public void Draw(SpriteBatch spriteBatch) 
    { 
     spriteBatch.Draw(Logo_Texture2d, Logo_Rec, Logo_color); 
     spriteBatch.DrawString(Norm_fonts, "CurrentState: Logo" + " Timer: " + ((int)_Timer_logo).ToString(), new Vector2(0, 0), Color.White); 
    } 
} 
} 

는 로고를 찾을 수 없습니다 때문에 디버깅 중지 및 내 이미지 형식은 너무 .png를한다 형식이 아닙니다.

답변

1

XNA가 컴파일되면 텍스쳐, 사운드, 음악, 글꼴 등의 모든 에셋을 .xnb 파일로 가져와 처리합니다. 텍스처의 표준 파일 형식은 .png입니다.

텍스처를 찾을 수 없다면 아마도 텍스처를 가져올 수 없다는 뜻입니다. 솔루션 탐색기에서 ProjectNameContent (Content) -> Add -> Existing Item을 마우스 오른쪽 단추로 클릭하여 내용을 추가하십시오.

이 작업을 완료하면 텍스처의 내용 가져 오기 도구와 콘텐츠 프로세서 속성이 모두 "텍스처 - XNA Framework"로 설정되어 있는지 확인하십시오.

참고로, 각 단계마다 MainFile.Update() 내에서 Logo.Load()를 호출하고 있습니다.이 설정을 변경하는 것이 좋습니다.

+0

내 텍스처가이 이미지를로드하는 데 사용하는 내용에 있지만이 오류가 더 깊게 기록 될 때 유용합니다. 그 이미지가 어디 suceful 작동하지만 난이 오류가 계속 나타나는 일이 뭔지 모르겠다. – user2727653

+0

오, 나는 Logo.Load(); 나는 그 xD를 알아 차리지 못했다. – user2727653

0

다른 콘텐츠 관리자를 만드는 것이 이러한 문제를 해결하는 방법이 아닙니다.

이 문제를 해결하는 한 가지 방법은 메서드의 매개 변수로 Content에 대한 참조를 전달하는 것입니다. 예 :

class Foo 
{ 
    public void LoadContent(ContentManager content) 
    { 
      Logo_Texture2d = content.Load<Texture2D>("Logo"); 
    } 
} 

public class Game1 : Game 
{ 
    //... 
    protected override void LoadContent() 
    { 
      Foo.LoadContent(Content); 
    } 
} 

편집 : 또한 VS를 통해 콘텐츠를로드하고 있습니까? [ProjectName] 내용 (내용) -> 추가 -> 기존 항목을 마우스 오른쪽 단추로 클릭하십시오. 서브 클래스에서 Content를 사용해야하는 경우 그냥

+0

나는 이미 그와 비슷한 것을 가지고 있지만 서브 클래스가 내용 파일을 읽지 않는다고 생각한다. 메인 파일과 하위 클래스 로고의 두 코드를 넣을 것이다. – user2727653

+0

OP의 편집에 대한 응답으로 추가 답변이 추가되었습니다. 여기서 제공되는 것과 다른 주제를 다룹니다. –

0

... 확인, 해당 클래스에 Content을 통과, 아니면 GameComponent에서 상속하는 클래스를 설정, 그래서 당신은 단순히 Game.Content를 사용하여 콘텐츠 관리자에 액세스 할 수 있습니다 sholud.
다른 콘텐츠를 선언 할 필요가 없습니다.

+0

그것을 선언 할 필요가 없다면 왜 그 이미지가 적절한 위치에 있는지 그 이유를 알지 못합니다. – user2727653