Sfoglia il codice sorgente

Remove calls to Viewport so GlobalTransformation works.

Dominique Louis 1 mese fa
parent
commit
6419f9bed4

+ 6 - 5
CardsStarterKit/Core/Game/Blackjack/Game/BlackjackCardGame.cs

@@ -1071,6 +1071,8 @@ namespace Blackjack
                         animationComponent.EstimatedTimeForAnimationsCompletion().Ticks);
                 }
             }
+            var widthCenter = screenManager.BackbufferWidth / 2;
+            var heightCenter = screenManager.BackbufferHeight / 2;
 
             // Add a component for an empty stalling animation. This actually acts
             // as a timer.
@@ -1078,15 +1080,14 @@ namespace Blackjack
             animationComponent = new AnimatedGameComponent(this, texture, screenManager.SpriteBatch, screenManager.GlobalTransformation)
             {
                 CurrentPosition = new Vector2(
-                    this.Game.GraphicsDevice.Viewport.Bounds.Center.X - texture.Width / 2,
-                    this.Game.GraphicsDevice.Viewport.Bounds.Center.Y - texture.Height / 2),
+                    widthCenter - texture.Width / 2,
+                    heightCenter - texture.Height / 2),
                 Visible = false
             };
             this.Game.Components.Add(animationComponent);
 
             // Add a button to return to the main menu
-            Rectangle bounds = this.Game.GraphicsDevice.Viewport.Bounds;
-            Vector2 center = new Vector2(bounds.Center.X, bounds.Center.Y);
+            Vector2 center = new Vector2(widthCenter, heightCenter);
             Button backButton = new Button("ButtonRegular", "ButtonPressed",
                 screenManager.input, this, screenManager.SpriteBatch, screenManager.GlobalTransformation)
             {
@@ -1157,7 +1158,7 @@ namespace Blackjack
                             (Game.Components[componentIndex] as AnimatedCardsGameComponent);
                         animatedCard.AddAnimation(
                             new TransitionGameComponentAnimation(animatedCard.CurrentPosition,
-                            new Vector2(animatedCard.CurrentPosition.X, this.Game.GraphicsDevice.Viewport.Height))
+                            new Vector2(animatedCard.CurrentPosition.X, ScreenManager.BACK_BUFFER_HEIGHT))
                             {
                                 Duration = TimeSpan.FromSeconds(0.40),
                                 PerformWhenDone = RemoveComponent,

+ 2 - 2
CardsStarterKit/Core/Game/Blackjack/Misc/BetGameComponent.cs

@@ -96,7 +96,7 @@ namespace Blackjack
             // Calculate chips position for the chip buttons which allow placing the bet
             Rectangle size = chipsAssets[assetNames[0]].Bounds;
 
-            Rectangle bounds = spriteBatch.GraphicsDevice.Viewport.TitleSafeArea;
+            Rectangle bounds = new Rectangle(0, 0, ScreenManager.BACK_BUFFER_WIDTH, ScreenManager.BACK_BUFFER_HEIGHT);
 
             positions[chipsAssets.Count - 1] = new Vector2(bounds.Left + 10,
                 bounds.Bottom - size.Height - 80);
@@ -547,7 +547,7 @@ namespace Blackjack
 
             // Add transition animation
             chipComponent.AddAnimation(new TransitionGameComponentAnimation(positions[0],
-                new Vector2(GraphicsDevice.Viewport.Width / 2, insuranceYPosition))
+                new Vector2(ScreenManager.BACK_BUFFER_WIDTH / 2, insuranceYPosition))
             {
                 PerformBeforeStart = ShowComponent,
                 PerformBeforSartArgs = chipComponent,

+ 3 - 3
CardsStarterKit/Core/Game/BlackjackGame.cs

@@ -84,9 +84,9 @@ namespace Blackjack
             graphicsDeviceManager.PreferredBackBufferHeight = ScreenManager.BACK_BUFFER_HEIGHT;
             graphicsDeviceManager.ApplyChanges();
 
-            Rectangle bounds = graphicsDeviceManager.GraphicsDevice.Viewport.TitleSafeArea;
-            HeightScale = bounds.Height / ScreenManager.BACK_BUFFER_HEIGHT;
-            WidthScale = bounds.Width / ScreenManager.BACK_BUFFER_WIDTH;
+            float scale = screenManager.GlobalTransformation.M11; // uniform scale
+            HeightScale = scale;
+            WidthScale = scale;
         }
 
         /// <summary>

+ 5 - 5
CardsStarterKit/Core/Game/Misc/InputHelper.cs

@@ -38,11 +38,11 @@ namespace Blackjack
             this.screenManager = screenManager;
             texture = screenManager.Game.Content.Load<Texture2D>(Path.Combine("Images", "GamePadCursor"));
             spriteBatch = screenManager.SpriteBatch;
-            maxVelocity = (float)(screenManager.Game.GraphicsDevice.Viewport.Width +
-                                  screenManager.Game.GraphicsDevice.Viewport.Height) / 3000f;
+            maxVelocity = (float)(ScreenManager.BACK_BUFFER_WIDTH +
+                                  ScreenManager.BACK_BUFFER_HEIGHT) / 3000f;
 
-            drawPosition = new Vector2(screenManager.Game.GraphicsDevice.Viewport.Width / 2,
-                screenManager.Game.GraphicsDevice.Viewport.Height / 2);
+            drawPosition = new Vector2(ScreenManager.BACK_BUFFER_WIDTH / 2,
+                ScreenManager.BACK_BUFFER_HEIGHT / 2);
         }
 
         //public static InputHelper Instance
@@ -81,7 +81,7 @@ namespace Blackjack
                 * gameTime.ElapsedGameTime.Milliseconds
                 * maxVelocity;
             drawPosition = Vector2.Clamp(drawPosition, Vector2.Zero,
-                new Vector2(Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height)
+                new Vector2(ScreenManager.BACK_BUFFER_WIDTH, ScreenManager.BACK_BUFFER_HEIGHT)
                 - new Vector2(texture.Bounds.Width, texture.Bounds.Height));
         }
 

+ 1 - 1
CardsStarterKit/Core/Game/ScreenManager/MenuScreen.cs

@@ -257,7 +257,7 @@ namespace GameStateManagement
                 MenuEntry menuEntry = menuEntries[i];
 
                 // each entry is to be centered horizontally
-                position.X = ScreenManager.GraphicsDevice.Viewport.Width / 2 - menuEntry.GetWidth(this) / 2;
+                position.X = ScreenManager.BACK_BUFFER_WIDTH / 2 - menuEntry.GetWidth(this) / 2;
 
                 if (ScreenState == ScreenState.TransitionOn)
                     position.X -= transitionOffset * 256;

+ 3 - 4
CardsStarterKit/Core/Game/ScreenManager/ScreenManager.cs

@@ -97,6 +97,7 @@ namespace GameStateManagement
             set { traceEnabled = value; }
         }
 
+        Rectangle safeArea = new Rectangle(0, 0, BACK_BUFFER_WIDTH, BACK_BUFFER_HEIGHT);
         /// <summary>
         /// Returns the portion of the screen where drawing is safely allowed.
         /// </summary>
@@ -104,7 +105,7 @@ namespace GameStateManagement
         {
             get
             {
-                return Game.GraphicsDevice.Viewport.TitleSafeArea;
+                return safeArea;
             }
         }
 
@@ -304,12 +305,10 @@ namespace GameStateManagement
         /// </summary>
         public void FadeBackBufferToBlack(float alpha)
         {
-            Viewport viewport = GraphicsDevice.Viewport;
-
             spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, GlobalTransformation);
 
             spriteBatch.Draw(blankTexture,
-                             new Rectangle(0, 0, viewport.Width, viewport.Height),
+                             new Rectangle(0, 0, BACK_BUFFER_WIDTH, BACK_BUFFER_HEIGHT),
                              Color.Black * alpha);
 
             spriteBatch.End();

+ 2 - 3
CardsStarterKit/Core/Game/Screens/BackgroundScreen.cs

@@ -35,7 +35,7 @@ namespace Blackjack
         public override void LoadContent()
         {
             background = ScreenManager.Game.Content.Load<Texture2D>(Path.Combine("Images", "titlescreen"));
-            safeArea = ScreenManager.Game.GraphicsDevice.Viewport.TitleSafeArea;
+            safeArea = new Rectangle(0, 0, ScreenManager.BACK_BUFFER_WIDTH, ScreenManager.BACK_BUFFER_HEIGHT);
             base.LoadContent();
         }
 
@@ -61,8 +61,7 @@ namespace Blackjack
         {
             ScreenManager.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
 
-            ScreenManager.SpriteBatch.Draw(background, ScreenManager.GraphicsDevice.Viewport.Bounds,
-                Color.White * TransitionAlpha);
+            ScreenManager.SpriteBatch.Draw(background, safeArea, Color.White * TransitionAlpha);
 
             ScreenManager.SpriteBatch.End();
 

+ 1 - 2
CardsStarterKit/Core/Game/Screens/GameplayScreen.cs

@@ -64,8 +64,7 @@ namespace Blackjack
             inputHelper.Enabled = false;
 #endif
 
-            blackJackGame = new BlackjackCardGame(ScreenManager.GraphicsDevice.Viewport.Bounds,
-                new Vector2(safeArea.Left + safeArea.Width / 2 - 50, safeArea.Top + 20),
+            blackJackGame = new BlackjackCardGame(safeArea, new Vector2(safeArea.Left + safeArea.Width / 2 - 50, safeArea.Top + 20),
                 GetPlayerCardPosition, ScreenManager, theme);
 
 

+ 1 - 5
CardsStarterKit/Core/Game/Screens/InstructionScreen.cs

@@ -16,9 +16,6 @@ using Microsoft.Xna.Framework.Input;
 using Microsoft.Xna.Framework.Input.Touch;
 using System.IO;
 
-
-
-
 namespace Blackjack
 {
     class InstructionScreen : GameplayScreen
@@ -121,8 +118,7 @@ namespace Blackjack
             spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
 
             // Draw Background
-            spriteBatch.Draw(background, ScreenManager.GraphicsDevice.Viewport.Bounds,
-                 Color.White * TransitionAlpha);
+            spriteBatch.Draw(background, ScreenManager.SafeArea, Color.White * TransitionAlpha);
 
             if (isExit)
             {

+ 1 - 2
CardsStarterKit/Core/Game/Screens/OptionsMenu.cs

@@ -111,8 +111,7 @@ namespace Blackjack
             ScreenManager.SpriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
 
             // Draw the card back
-            ScreenManager.SpriteBatch.Draw(background, ScreenManager.GraphicsDevice.Viewport.Bounds,
-                Color.White * TransitionAlpha);
+            ScreenManager.SpriteBatch.Draw(background, ScreenManager.SafeArea, Color.White * TransitionAlpha);
 
             ScreenManager.SpriteBatch.End();
             base.Draw(gameTime);