我想在我的Map类中更改屏幕的标题。我知道Game1
你可以用this.Window.Title = "Level1";
而且我想LoadContent
在我的Map类的方法中将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的新实例,但由于它是抽象类,所以您不能这样做。
所以,当我跑我的游戏,它抛出一个NullReferenceExceptionError
上gameWindow.Title
。那是因为我无法创建GameWindow的实例。
是否有(不同的)解决方案来更改班级中的屏幕标题?
从Map调用LoadContent的代码:
map.LoadContent(this.Content, GraphicsDevice, this.Window);
感谢@ itsme86,使我可以使用以下代码:
该方法调用在Game1
:map.LoadContent(this.Content, GraphicsDevice, this);
LoadContent
地图类中的方法:
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;
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句