TouchCollectionExtensions.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // TouchCollectionExtensions.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. using Microsoft.Xna.Framework.Input.Touch;
  10. namespace Platformer
  11. {
  12. /// <summary>
  13. /// Provides extension methods for the TouchCollection type.
  14. /// </summary>
  15. public static class TouchCollectionExtensions
  16. {
  17. /// <summary>
  18. /// Determines if there are any touches on the screen.
  19. /// </summary>
  20. /// <param name="touchState">The current TouchCollection.</param>
  21. /// <returns>True if there are any touches in the Pressed or Moved state, false otherwise</returns>
  22. public static bool AnyTouch(this TouchCollection touchState)
  23. {
  24. foreach (TouchLocation location in touchState)
  25. {
  26. if (location.State == TouchLocationState.Pressed || location.State == TouchLocationState.Moved)
  27. {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33. }
  34. }