2017-02-03 6 views
0

を使用してスプライトサイズを拡大するため、私は現在ゲームの解像度の独立性に取り組んでおり、剣のイメージでテストしています。ポジションの変更は機能していますが、サイズを開始するたびに空白の画面が表示されます。ベクトル2 Monogame C#

これらは、スプライトの新しい位置とサイズを取得するために実行する関数です。私は(

更新において
swordTexture = content.Load<Texture2D>("SOLDIER_Sword"); 
swordPosition = new Vector2(300, 0); 
swordRefSize = new Vector2(557, 490); 
swordSize = new Vector2(557, 490); 
swordRefPosition = new Vector2(300, 0); 
swordColor = Color.White; 
sword = new StaticSprite(swordTexture, swordPosition, swordSize, swordColor); 

毎回画面解像度変更:私はこれを実行するロード機能で

graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; 
graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; 
swordPosition = CalculateNewPos(swordRefPosition, new Vector2(1920, 1080), new Vector2(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height)); 
swordSize = CalculateNewSize(swordRefSize, new Vector2(1920, 1080), new Vector2(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height)); 

:Game1で初期化関数で

private static float CalcRatio(Vector2 size) 
    { 
     return size.Y/size.X; 
    } 

    public static Vector2 CalculateNewPos(Vector2 refPos, Vector2 refScreenSize, Vector2 currentScreenSize) 
    { 
     return new Vector2((refPos.X/refScreenSize.X) * currentScreenSize.X, 
          (refPos.Y/refScreenSize.Y) * currentScreenSize.Y); 
    } 

    public static Vector2 CalculateNewSize(Vector2 refSize, Vector2 refScreenSize, Vector2 currenScreenSize) 
    { 
     float origRatio = CalcRatio(refSize); 
     float perW = refSize.X * 100f/refScreenSize.X; 
     float newW = perW/100f * currenScreenSize.X; 
     float newH = newW * origRatio; 
     return new Vector2(newW, newH); 
    } 

私はこのコードを実行しますボタンはこれを行うように設定されています):

graphics.PreferredBackBufferHeight = setHeight; 
graphics.PreferredBackBufferWidth = setWidth; 
graphics.ApplyChanges(); 
swordPosition = CalculateNewPos(swordRefPosition, new Vector2(1920, 1080), new Vector2(setWidth, setHeight)); 
swordSize = CalculateNewSize(swordRefSize, new Vector2(1920, 1080), new Vector2(setWidth, setHeight)); 

ドローに:

batch.Draw(swordTexture, swordPosition, null, swordColor, 0f, Vector2.Zero, swordSize, SpriteEffects.None, 0f); 

そんなにコードがあり申し訳ありませんが、私は本当に困惑し、それが間違って起こっている場所を特定することはできませんので、私はただの変数を変更するすべてのものが含まれています。

これを見ていただきありがとうございます。

+0

この質問について私が書き込んだ答えを見てみることができます:http://stackoverflow.com/questions/18645032/change-and-scale-resolution-of-xna-game/20813250#20813250 – Falgantil

+0

表示モードは、フルスクリーンの場合にのみ意味があります。これは、スプライトバッチの投影行列の幅/高さを示すVIEWPORTです。 – James

答えて

0

現在の表示モードは、フルスクリーン表示の場合にのみ意味があることに注意してください。これは、スプライトバッチの投影行列の幅/高さを示すVIEWPORTです。

あなたは通常、個々のアイテムを再スケーリングしたくないので、Bjarkeの投稿を実際に調べる必要があります。