【问题标题】:How to get resolution of silverlight + XNA application如何获得silverlight + XNA应用程序的分辨率
【发布时间】:2013-10-26 09:57:12
【问题描述】:

我正在使用 Silverlight 和 XNA 框架开发游戏。我想获取移动屏幕的高度和宽度,以便在任何设备上运行应用程序。意味着所有设备都应支持应用程序的扩展。

public partial class GamePage : PhoneApplicationPage
{
   public static ContentManager contentManager;
   GameTimer timer;
   SpriteBatch spriteBatch;
   GraphicsDeviceManager graphics;

   public GamePage()
   {
        InitializeComponent();

        //error at below line 
        graphics = new GraphicsDeviceManager(this);

        contentManager = (System.Windows.Application.Current as App).Content;

        rand = new Random();

        // Create a timer for this page
        timer = new GameTimer();
        timer.UpdateInterval = TimeSpan.FromTicks(333333);
        timer.Update += OnUpdate;
        timer.Draw += OnDraw;
    }

【问题讨论】:

    标签: c# silverlight xna


    【解决方案1】:

    请注意,我不确定这是否可以在移动设备上使用。 GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width or Height 会给你设备的屏幕分辨率,

    graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height
    graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width
    graphics.ApplyChanges();
    

    编辑:

    使用 silverlight 你必须这样做:

    Application.Current.Host.Content.ActualHeight;
    Application.Current.Host.Content.ActualWidth;
    

    另请注意,GraphicsDevciceManager 的 silverlight 等效项是 SharedGraphicsDeviceManager

    【讨论】:

    • 它可用,但仅在 xna 游戏中可用....如果你正在做 xna plus silverlight,那么它会给出错误
    • Microdoft.XNA.framework.graphicsdevicemanager(micorsoft.xna.framework.game)的最佳重载方法匹配有一些无效的争论
    • 如果我在这一行中进行更改,则该错误已解决,但其他方法给出错误类 GamePage : Microsoft.XNA.Game
    • 实际错误是什么?也尝试使用SharedGraphicsDeviceManager
    【解决方案2】:

    Application.Current.RootVisual.RenderSize 应该会给你这些信息。

    或者你可以试试:

    int ScreenWidth = Application.Current.Host.Content.ActualWidth;  
    int ScreenHeight = Application.Current.Host.Content.ActualHeight;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-15
      • 2011-04-13
      • 1970-01-01
      • 1970-01-01
      • 2017-12-21
      相关资源
      最近更新 更多