Autor Beitrag
C#
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 561
Erhaltene Danke: 65

Windows 10, Kubuntu, Android
Visual Studio 2017, C#, C++/CLI, C++/CX, C++, F#, R, Python
BeitragVerfasst: Mo 02.01.12 18:55 
Hallo,
ich bin vor kurzem auf XNA gestoßen - bin also Neuling. Wenn ich jetzt mein Game Lade, kommt beim Laden einer SpriteFont die oben genannte Exception.
Ich Lade diese Font außerhalb der LoadContent Methode. Genauergesagt in einer anderen Klasse.
Hier der Code:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
namespace xyz
{
    public partial class Game1 : Game
    {
  //Variablendeklaration...

        protected GraphicsDeviceManager graphics;
        protected SpriteBatch spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        protected override void LoadContent()
        {         
            Video video = Content.Load<Video>("Intro");
            videoPlayer.Play(video);
            GameMode = GameMode.None;
            font = Content.Load<SpriteFont>("Courier New");
            spriteBatch = new SpriteBatch(GraphicsDevice);
            player.Texture = Content.Load<Texture2D>("breaker");
            player.Speed = SCREENWIDTH / 10;
            Menu.Load();
            GameState = GameState.Loaded;
        }
    }
}

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
namespace xyz
{
    public class Menu : Game1
    {        

  //...
  public void Load()
        {
            StringStartPosition = WINDOW.Height / 5;
            StringDistance = WINDOW.Height / 10;
            Font = Content.Load<SpriteFont>("MenuFont"); //Hier tritt die Exception auf
            Strings.Add(new SelectableString("You vs the Clock", Font, "Reach the goal as fast as you can. The clock is ticking!"));
            Strings.Add(new SelectableString("Apocalyptic Mode", Font, "Reach the goal as fast as you can. You have weapons and other usefull things. Use them! The clock is ticking!"));
            Strings.Add(new SelectableString("Create Map", Font, "Create your own maps and play them."));
            Strings.Add(new SelectableString("Options", Font, "Change the settings of the game"));
            Strings.Add(new SelectableString("Exit", Font, "Leave the game. Are you sure?"));
            Background = Content.Load<Texture2D>("Menu");
            Color = Set.MenuColor;
            SelectionColor = Set.MenuSelectedColor;
            Strings[0].Select = true;
            SelectedString = 0;
            InfoText = Strings[0].TextInfo;
        }
  //...
    }
}


Weiß jemand wie ich das beheben kann?

_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Mo 02.01.12 19:38 
Hallo C#,

mir erscheint dein Klassendesign etwas eigenartig zu sein: du leitest Menu von Game1 ab, so daß es also selber vom Typ Game ist. Ich denka aber, daß es in XNA nur genau eine Game-Klasse (bzw. Instanz) geben sollte.

Außerdem hast du schon mal im Internet nach deiner Fehlermeldung geschaut, z.B.
stackoverflow.com/qu...-my-c-sharp-xna-game
forums.create.msdn.com/forums/t/26469.aspx
www.xnamag.de/forum/viewtopic.php?p=34432
C# Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 561
Erhaltene Danke: 65

Windows 10, Kubuntu, Android
Visual Studio 2017, C#, C++/CLI, C++/CX, C++, F#, R, Python
BeitragVerfasst: Mo 02.01.12 23:45 
Danke. Ich habe das Problem jetzt gelöst. Ich habe über eine weitere, statische Klasse diw Wichtigsten Objekte aufgelistet. So habe ich auch einen Zeiger auf meine Game1-Klasse. Über diesen Zeiger kann ich problemlos die Contents laden.

_________________
Der längste Typ-Name im .NET-Framework ist: ListViewVirtualItemsSelectionRangeChangedEventHandler