2013-10-26 92 views
0

我正在開發一款使用Silverlight和XNA框架的遊戲。我想獲得移動屏幕的高度和寬度,以便在任何設備上運行應用程序。應該支持所有設備的應用程序擴展。如何獲得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; 
    } 

回答

2

請注意我不確定這是否在手機上可用。 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

+0

它是可用,但只有在XNA遊戲....如果你正在做的XNA加的Silverlight則給出了錯誤 – pravin

+0

這是什麼錯誤? – Cyral

+0

與Microdoft.XNA.framework.graphicsdevicemanager(micorsoft.xna.framework.game)匹配的最佳重載方法有一些無效的爭論 – pravin

1

Application.Current.RootVisual.RenderSize應該給你t帽子信息。

或者你可以嘗試:

int ScreenWidth = Application.Current.Host.Content.ActualWidth; 
int ScreenHeight = Application.Current.Host.Content.ActualHeight; 
相關問題