Search code examples
c#visual-studio-2010windows-phone-7xna-4.0

XNA Game Classes


Since I need mulitple screens, 1) can I define more than one game class(inherited from Microsoft.Xna.Framework.Game and with different class names). 2) is there any design flaws creating in such way?


Solution

  • I don't think this is possible on Windows Phone 7. The platform starts an XNA game by finding a class derived from Game to instance (unlike Xbox and Windows where you create the instance yourself). I suspect it will fail if you have more than one derived class. (You could try it.)

    Then there is the issue of the GraphicsDevice. I suspect it's not possible to set up two instances of the graphics device on WP7. How do you change which one can write to the screen? I'm not aware of any API for doing this.

    Also, if you did have two separate graphics devices - you couldn't share content between the two. You would have to load it twice - a performance issue.

    In theory you can set up two instances of Game to use the one GraphicsDevice. But that involves writing your own replacement version of GraphicsDeviceManager. That's not an easy task - and certainly much harder than simply setting up a simple state machine to handle your different screens.

    Perhaps check out the Game State Management sample for an example of how it's supposed to be done.