XNA修改为MonoGame好处很多,最大的好处是放广告。目前很多广告平台已经不支持WP7。XNA项目丢之可惜,所有修改成MonoGame是个最佳选择。

靠复制代码,修改音频播放类,还需要解决WP8多种分辨率的问题。直接上代码:

GamePage.xaml:


 
 
 

GamePage.cs:

public partial class GamePage : PhoneApplicationPage
    {
        public static GamePage Instance = null;
        private Game1 _game;

        // Constructor
        public GamePage()
        {
            InitializeComponent();
            if (Instance != null)
                throw new InvalidOperationException("There can be only one GamePage object!");

            Instance = this;
           
            
            _game = XamlGame.Create("", this);
            SetupScreenAutoScaling();
            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }
        private void SetupScreenAutoScaling()
        {

            // Get the screen’s WVGA ''ScaleFactor'' via reflection.  scaleFactor will be 100 (WVGA), 160 (WXGA), or 150 (WXGA).
            int? scaleFactor = null;
            var content = App.Current.Host.Content;
            var scaleFactorProperty = content.GetType().GetProperty("ScaleFactor");

            if (scaleFactorProperty != null)
                scaleFactor = scaleFactorProperty.GetValue(content, null) as int?;

            if (scaleFactor == null)
                scaleFactor = 100; // 100% WVGA resolution

            double scale = ((double)scaleFactor) / 100.0; //scale from WVGA to Viewport Bounds

            // For 720P, we will scale to 150% WVGA resolution, resulting in a 1200x720 viewport inside a 1280x720 screen,
            // which is why letterboxing will be required.  By centering the viewport on the screen, it will be less noticeable.

            if (scaleFactor == 150)
            {
                // Centered letterboxing - move Margin.Left to the right by ((1280-1200)/2)/scale
                //GamePage.Instance.XnaSurface.Margin = new System.Windows.Thickness(40 / scale, 0, 0, 0);
            }

            // Scale the XnaSurface: 

            ScaleTransform scaleTransform = new ScaleTransform();
            scaleTransform.ScaleX = scaleTransform.ScaleY = scale;
            GamePage.Instance.XnaSurface.RenderTransform = scaleTransform;
        }
        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    }