ScreenFactory.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // ScreenFactory.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. using System;
  10. using GameStateManagement;
  11. namespace GameStateManagementSample
  12. {
  13. /// <summary>
  14. /// Our game's implementation of IScreenFactory which can handle creating the screens
  15. /// when resuming from being tombstoned.
  16. /// </summary>
  17. public class ScreenFactory : IScreenFactory
  18. {
  19. public GameScreen CreateScreen(Type screenType)
  20. {
  21. // All of our screens have empty constructors so we can just use Activator
  22. return Activator.CreateInstance(screenType) as GameScreen;
  23. // If we had more complex screens that had constructors or needed properties set,
  24. // we could do that before handing the screen back to the ScreenManager. For example
  25. // you might have something like this:
  26. //
  27. // if (screenType == typeof(MySuperGameScreen))
  28. // {
  29. // bool value = GetFirstParameter();
  30. // float value2 = GetSecondParameter();
  31. // MySuperGameScreen screen = new MySuperGameScreen(value, value2);
  32. // return screen;
  33. // }
  34. //
  35. // This lets you still take advantage of constructor arguments yet participate in the
  36. // serialization process of the screen manager. Of course you need to save out those
  37. // values when deactivating and read them back, but that means either IsolatedStorage or
  38. // using the PhoneApplicationService.Current.State dictionary.
  39. }
  40. }
  41. }