Browse Source

Remove __IOS__ as not valid with .Core libraries. Replaces with OS call to check for iOS.

Dominique Louis 10 months ago
parent
commit
14e5527425

+ 8 - 6
AutoPong/AutoPong.Core/AutoPongGame.cs

@@ -1,7 +1,7 @@
-using Microsoft.Xna.Framework;
+using System;
+using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Graphics;
 using Microsoft.Xna.Framework.Input;
-using System;
 
 namespace AutoPong
 {
@@ -48,10 +48,12 @@ namespace AutoPong
 
         protected override void Update(GameTime gameTime)
         {
-#if !__IOS__
-            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
-                Exit();
-#endif
+            if (OperatingSystem.IsIOS())
+            {
+                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
+                    Exit();
+            }
+
             #region Update Ball
 
             //limit how fast ball can move each frame

+ 12 - 13
NeonShooter/NeonShooter.Core/Game/GameRoot.cs

@@ -3,15 +3,12 @@
 // Find the full tutorial at: http://gamedev.tutsplus.com/series/vector-shooter-xna/
 //----------------------------------------------------------------------------------
 
+using System;
 using BloomPostprocess;
 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Graphics;
 using Microsoft.Xna.Framework.Input;
-using System;
-
-#if !__IOS__
 using Microsoft.Xna.Framework.Media;
-#endif
 
 namespace NeonShooter
 {
@@ -58,10 +55,11 @@ namespace NeonShooter
 
 			EntityManager.Add(PlayerShip.Instance);
 
-#if !__IOS__
-			MediaPlayer.IsRepeating = true;
-			MediaPlayer.Play(Sound.Music);
-#endif
+			if (OperatingSystem.IsIOS())
+			{
+				MediaPlayer.IsRepeating = true;
+				MediaPlayer.Play(Sound.Music);
+			}
 		}
 
 		protected override void LoadContent()
@@ -76,11 +74,12 @@ namespace NeonShooter
 			GameTime = gameTime;
 			Input.Update();
 
-#if !__IOS__
-			// Allows the game to exit
-			if (Input.WasButtonPressed(Buttons.Back) || Input.WasKeyPressed(Keys.Escape))
-				this.Exit();
-#endif
+			if (OperatingSystem.IsIOS())
+			{
+				// Allows the game to exit
+				if (Input.WasButtonPressed(Buttons.Back) || Input.WasKeyPressed(Keys.Escape))
+					this.Exit();
+			}
 
 			if (Input.WasKeyPressed(Keys.P))
 				paused = !paused;

+ 18 - 20
NeonShooter/NeonShooter.Core/NeonShooterGame.cs

@@ -1,12 +1,9 @@
+using System;
 using BloomPostprocess;
 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Graphics;
 using Microsoft.Xna.Framework.Input;
-using System;
-
-#if !__IOS__
 using Microsoft.Xna.Framework.Media;
-#endif
 
 namespace NeonShooter
 {
@@ -73,19 +70,19 @@ namespace NeonShooter
 
             EntityManager.Add(PlayerShip.Instance);
 
-
-#if !__IOS__
-            //Known issue that you get exceptions if you use Media PLayer while connected to your PC
-            //See http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/c8a243d2-d360-46b1-96bd-62b1ef268c66
-            //Which means its impossible to test this from VS.
-            //So we have to catch the exception and throw it away
-            try
+            if (OperatingSystem.IsIOS())
             {
-                MediaPlayer.IsRepeating = true;
-                MediaPlayer.Play(Sound.Music);
+                //Known issue that you get exceptions if you use Media PLayer while connected to your PC
+                //See http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/c8a243d2-d360-46b1-96bd-62b1ef268c66
+                //Which means its impossible to test this from VS.
+                //So we have to catch the exception and throw it away
+                try
+                {
+                    MediaPlayer.IsRepeating = true;
+                    MediaPlayer.Play(Sound.Music);
+                }
+                catch { }
             }
-            catch { }
-#endif
         }
 
         /// <summary>
@@ -98,11 +95,12 @@ namespace NeonShooter
             GameTime = gameTime;
             Input.Update();
 
-#if !__IOS__
-            // Allows the game to exit
-            if (Input.WasButtonPressed(Buttons.Back) || Input.WasKeyPressed(Keys.Escape))
-                this.Exit();
-#endif
+            if (OperatingSystem.IsIOS())
+            {
+                // Allows the game to exit
+                if (Input.WasButtonPressed(Buttons.Back) || Input.WasKeyPressed(Keys.Escape))
+                    this.Exit();
+            }
 
             if (Input.WasKeyPressed(Keys.P))
                 paused = !paused;

+ 20 - 19
Platformer2D/Platformer2D.Core/PlatformerGame.cs

@@ -10,14 +10,11 @@
 using System;
 using System.IO;
 using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Content;
 using Microsoft.Xna.Framework.Graphics;
 using Microsoft.Xna.Framework.Input;
 using Microsoft.Xna.Framework.Input.Touch;
-using Microsoft.Xna.Framework.Content;
-
-#if !__IOS__
 using Microsoft.Xna.Framework.Media;
-#endif
 
 namespace Platformer2D
 {
@@ -102,18 +99,20 @@ namespace Platformer2D
 
             virtualGamePad = new VirtualGamePad(baseScreenSize, globalTransformation, Content.Load<Texture2D>("Sprites/VirtualControlArrow"));
 
-#if !__IOS__
-            //Known issue that you get exceptions if you use Media PLayer while connected to your PC
-            //See http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/c8a243d2-d360-46b1-96bd-62b1ef268c66
-            //Which means its impossible to test this from VS.
-            //So we have to catch the exception and throw it away
-            try
+            if (OperatingSystem.IsIOS())
             {
-                MediaPlayer.IsRepeating = true;
-                MediaPlayer.Play(Content.Load<Song>("Sounds/Music"));
+                //Known issue that you get exceptions if you use Media PLayer while connected to your PC
+                //See http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/c8a243d2-d360-46b1-96bd-62b1ef268c66
+                //Which means its impossible to test this from VS.
+                //So we have to catch the exception and throw it away
+                try
+                {
+                    MediaPlayer.IsRepeating = true;
+                    MediaPlayer.Play(Content.Load<Song>("Sounds/Music"));
+                }
+                catch { }
             }
-            catch { }
-#endif
+
             LoadNextLevel();
         }
 
@@ -164,11 +163,13 @@ namespace Platformer2D
             gamePadState = virtualGamePad.GetState(touchState, GamePad.GetState(PlayerIndex.One));
             accelerometerState = Accelerometer.GetState();
 
-#if !NETFX_CORE && !__IOS__
-            // Exit the game when back is pressed.
-            if (gamePadState.Buttons.Back == ButtonState.Pressed)
-                Exit();
-#endif
+            if (OperatingSystem.IsIOS())
+            {
+                // Exit the game when back is pressed.
+                if (gamePadState.Buttons.Back == ButtonState.Pressed)
+                    Exit();
+            }
+
             bool continuePressed =
                 keyboardState.IsKeyDown(Keys.Space) ||
                 gamePadState.IsButtonDown(Buttons.A) ||