TilemapImageLayer.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Graphics;
  4. namespace MonoGame.Extended.Tilemaps
  5. {
  6. /// <summary>
  7. /// Represents a layer that displays a single image.
  8. /// </summary>
  9. public class ImageLayer : TilemapLayer
  10. {
  11. /// <summary>
  12. /// Gets or sets the image texture displayed by this layer.
  13. /// </summary>
  14. public Texture2D Texture { get; set; }
  15. /// <summary>
  16. /// Gets or sets the position of the image.
  17. /// </summary>
  18. public Vector2 Position { get; set; }
  19. /// <summary>
  20. /// Gets or sets a value indicating whether the image repeats horizontally.
  21. /// </summary>
  22. public bool RepeatX { get; set; }
  23. /// <summary>
  24. /// Gets or sets a value indicating whether the image repeats vertically.
  25. /// </summary>
  26. public bool RepeatY { get; set; }
  27. /// <inheritdoc/>
  28. public override Rectangle Bounds
  29. {
  30. get
  31. {
  32. if (Texture == null)
  33. {
  34. return Rectangle.Empty;
  35. }
  36. // For repeating images, bounds are theoretically infinite
  37. // Return the base texture size at the layer's position
  38. return new Rectangle(
  39. (int)Position.X,
  40. (int)Position.Y,
  41. Texture.Width,
  42. Texture.Height
  43. );
  44. }
  45. }
  46. /// <summary>
  47. /// Initializes a new instance of the <see cref="ImageLayer"/> class.
  48. /// </summary>
  49. /// <param name="name">The name of the layer.</param>
  50. /// <param name="texture">The image texture.</param>
  51. /// <param name="position">The position of the image.</param>
  52. public ImageLayer(string name, Texture2D texture, Vector2 position) : base(name)
  53. {
  54. Texture = texture;
  55. Position = position;
  56. }
  57. }
  58. }