2014-12-14 5 views
1

내지도 클래스에서 화면의 제목을 변경하고 싶습니다. 나는 Game1 당신이
this.Window.Title = "Level1";클래스의 xna 화면 제목을 변경하는 방법

사용할 수 있다는 것을 알고 그리고 난 내지도 클래스에 내 LoadContent 방법 매개 변수로 GameWindow를 제공 문질러서.

public class Map 
{ 
    public void LoadContent(ContentManager content, GraphicsDevice graphicsDevice, GameWindow gamewindow) 
    { 
     switch (currentLevel) 
     { 
      case 1: 
       texture1 = content.Load<Texture2D>("skyLine"); 
       song = content.Load<Song>("music"); 
       gamewindow.Title = "Level 1"; 
       MediaPlayer.Play(song); 
       break; 
     } 
    } 
} 

내 Game1에서는 GameWindow의 새 인스턴스를 만들려고했으나 추상 클래스이므로 실행할 수 없습니다.

그래서 내 게임을 실행할 때 NullReferenceExceptionErrorgameWindow.Title에 던집니다. GameWindow의 인스턴스를 만들 수 없기 때문에 그렇습니다.

클래스의 화면 제목을 변경하는 (다른) 솔루션이 있습니까?

코드지도에서 LoadContent 전화 :

메서드 호출 Game1에서 : map.LoadContent(this.Content, GraphicsDevice, this);

LoadContent 방법 나는 그것이 다음 코드를 사용하여 작업있어 itsme86 @에

map.LoadContent(this.Content, GraphicsDevice, this.Window); 
+0

이 클래스의 호출자가 사용할 수있는 새 제목 집합을 찾았습니까? 뭔가가 무효화 될 수 있습니다 – Saravanan

+0

'this.Window'를 해당 LoadContent() 메서드에 전달하고 있습니까? – itsme86

+0

@ itsme86 나는 또한 그것을 시도했다. 여전히 NullReferenceException을 던진다. – Bas

답변

2

감사합니다 지도 클래스에서 :

public class Map 
{ 
    public void LoadContent(ContentManager content, GraphicsDevice graphicsDevice, Game1 game) 
    { 
     switch (currentLevel) 
     { 
       case 1: 
        texture1 = content.Load<Texture2D>("skyLine"); 
        song = content.Load<Song>("music"); 
        game.Window.Title = "Level 1"; 
        MediaPlayer.Play(song); 
       break; 
     } 
    } 
} 
관련 문제