diff --git a/Source/Demos/Demo.Camera/Game1.cs b/Source/Demos/Demo.Camera/Game1.cs index 5a7f39c8..16aeeb5f 100644 --- a/Source/Demos/Demo.Camera/Game1.cs +++ b/Source/Demos/Demo.Camera/Game1.cs @@ -158,7 +158,7 @@ namespace Demo.Camera } // not all sprite batches need to be affected by the camera - var rectangle = _camera.GetBoundingRectangle(); + var rectangle = _camera.BoundingRectangle; var stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"WASD: Move [{_camera.Position.X:0}, {_camera.Position.Y:0}]"); stringBuilder.AppendLine($"EQ: Rotate [{MathHelper.ToDegrees(_camera.Rotation):0.00}]"); diff --git a/Source/Demos/Demo.SceneGraphs/Game1.cs b/Source/Demos/Demo.SceneGraphs/Game1.cs index a6f80f30..7a6748b1 100644 --- a/Source/Demos/Demo.SceneGraphs/Game1.cs +++ b/Source/Demos/Demo.SceneGraphs/Game1.cs @@ -144,7 +144,7 @@ namespace Demo.SceneGraphs if (_hoveredNode != null) { - var boundingRectangle = _hoveredNode.GetBoundingRectangle(); + var boundingRectangle = _hoveredNode.BoundingRectangle; _spriteBatch.DrawRectangle(boundingRectangle, Color.Black); } diff --git a/Source/Demos/Demo.SpriteSheetAnimations/Content/Project1.mgcf b/Source/Demos/Demo.SpriteSheetAnimations/Content/Project1.mgcf new file mode 100644 index 00000000..54cfbaf6 --- /dev/null +++ b/Source/Demos/Demo.SpriteSheetAnimations/Content/Project1.mgcf @@ -0,0 +1,3 @@ +{ + "PublishPath": "D:\\Github\\Private\\AstridAnimator\\AstridAnimator\\bin\\Debug" +} \ No newline at end of file diff --git a/Source/Demos/Demo.SpriteSheetAnimations/Zombie.cs b/Source/Demos/Demo.SpriteSheetAnimations/Zombie.cs index 13264cae..e0e7a853 100644 --- a/Source/Demos/Demo.SpriteSheetAnimations/Zombie.cs +++ b/Source/Demos/Demo.SpriteSheetAnimations/Zombie.cs @@ -29,7 +29,7 @@ namespace Demo.SpriteSheetAnimations private ZombieState _state; - public RectangleF BoundingBox => _sprite.GetBoundingRectangle(); + public RectangleF BoundingBox => _sprite.BoundingRectangle; public bool IsOnGround { get; private set; } diff --git a/Source/MonoGame.Extended.Tests/Camera2DTests.cs b/Source/MonoGame.Extended.Tests/Camera2DTests.cs index e7112972..c85dfc9e 100644 --- a/Source/MonoGame.Extended.Tests/Camera2DTests.cs +++ b/Source/MonoGame.Extended.Tests/Camera2DTests.cs @@ -39,7 +39,7 @@ namespace MonoGame.Extended.Tests } [Test] - public void Camera2D_GetBoundingRectangle_Test() + public void Camera2D_BoundingRectangle_Test() { var graphicsDevice = TestHelper.CreateGraphicsDevice(); var viewport = new DefaultViewportAdapter(graphicsDevice); @@ -47,7 +47,7 @@ namespace MonoGame.Extended.Tests camera.Move(new Vector2(2, 0)); camera.Move(new Vector2(0, 3)); - var boundingRectangle = camera.GetBoundingRectangle(); + var boundingRectangle = camera.BoundingRectangle; Assert.AreEqual(2, boundingRectangle.Left, 0.01); Assert.AreEqual(3, boundingRectangle.Top, 0.01); diff --git a/Source/MonoGame.Extended.Tests/Sprites/SpriteTests.cs b/Source/MonoGame.Extended.Tests/Sprites/SpriteTests.cs index 78a1f828..34a4b9bb 100644 --- a/Source/MonoGame.Extended.Tests/Sprites/SpriteTests.cs +++ b/Source/MonoGame.Extended.Tests/Sprites/SpriteTests.cs @@ -21,7 +21,7 @@ namespace MonoGame.Extended.Tests.Sprites Position = new Vector2(400, 240) }; - Assert.AreEqual(new RectangleF(375, 140, 50, 200), sprite.GetBoundingRectangle()); + Assert.AreEqual(new RectangleF(375, 140, 50, 200), sprite.BoundingRectangle); } [Test] @@ -34,7 +34,7 @@ namespace MonoGame.Extended.Tests.Sprites OriginNormalized = new Vector2(1.0f, 1.0f) }; - Assert.AreEqual(new RectangleF(-50, -200, 50, 200), sprite.GetBoundingRectangle()); + Assert.AreEqual(new RectangleF(-50, -200, 50, 200), sprite.BoundingRectangle); } [Test] @@ -47,7 +47,7 @@ namespace MonoGame.Extended.Tests.Sprites Scale = Vector2.One * 2.0f }; - Assert.AreEqual(new RectangleF(-50, -200, 100, 400), sprite.GetBoundingRectangle()); + Assert.AreEqual(new RectangleF(-50, -200, 100, 400), sprite.BoundingRectangle); } [Test] @@ -60,7 +60,7 @@ namespace MonoGame.Extended.Tests.Sprites Rotation = MathHelper.ToRadians(90) }; - Assert.AreEqual(new RectangleF(-100, -25, 200, 50), sprite.GetBoundingRectangle()); + Assert.AreEqual(new RectangleF(-100, -25, 200, 50), sprite.BoundingRectangle); } [Test] diff --git a/Source/MonoGame.Extended/Camera2D.cs b/Source/MonoGame.Extended/Camera2D.cs index eb67a717..8fdea154 100644 --- a/Source/MonoGame.Extended/Camera2D.cs +++ b/Source/MonoGame.Extended/Camera2D.cs @@ -175,15 +175,18 @@ namespace MonoGame.Extended return new BoundingFrustum(projectionMatrix); } - public RectangleF GetBoundingRectangle() + public RectangleF BoundingRectangle { - var frustum = GetBoundingFrustum(); - var corners = frustum.GetCorners(); - var topLeft = corners[0]; - var bottomRight = corners[2]; - var width = bottomRight.X - topLeft.X; - var height = bottomRight.Y - topLeft.Y; - return new RectangleF(topLeft.X, topLeft.Y, width, height); + get + { + var frustum = GetBoundingFrustum(); + var corners = frustum.GetCorners(); + var topLeft = corners[0]; + var bottomRight = corners[2]; + var width = bottomRight.X - topLeft.X; + var height = bottomRight.Y - topLeft.Y; + return new RectangleF(topLeft.X, topLeft.Y, width, height); + } } public ContainmentType Contains(Point point) diff --git a/Source/MonoGame.Extended/SceneGraphs/ISceneEntity.cs b/Source/MonoGame.Extended/SceneGraphs/ISceneEntity.cs index 46325976..d648a22f 100644 --- a/Source/MonoGame.Extended/SceneGraphs/ISceneEntity.cs +++ b/Source/MonoGame.Extended/SceneGraphs/ISceneEntity.cs @@ -7,7 +7,7 @@ namespace MonoGame.Extended.SceneGraphs { public interface ISceneEntity { - RectangleF GetBoundingRectangle(); + RectangleF BoundingRectangle { get; } } public interface ISpriteBatchDrawable diff --git a/Source/MonoGame.Extended/SceneGraphs/SceneGraph.cs b/Source/MonoGame.Extended/SceneGraphs/SceneGraph.cs index a10612f2..4d03a185 100644 --- a/Source/MonoGame.Extended/SceneGraphs/SceneGraph.cs +++ b/Source/MonoGame.Extended/SceneGraphs/SceneGraph.cs @@ -22,9 +22,9 @@ namespace MonoGame.Extended.SceneGraphs { var node = RootNode; - while (node != null && node.GetBoundingRectangle().Contains(x, y)) + while (node != null && node.BoundingRectangle.Contains(x, y)) { - var childNode = node.Children.FirstOrDefault(c => c.GetBoundingRectangle().Contains(x, y)); + var childNode = node.Children.FirstOrDefault(c => c.BoundingRectangle.Contains(x, y)); if(childNode != null) node = childNode; diff --git a/Source/MonoGame.Extended/SceneGraphs/SceneNode.cs b/Source/MonoGame.Extended/SceneGraphs/SceneNode.cs index b40d677e..da4e2960 100644 --- a/Source/MonoGame.Extended/SceneGraphs/SceneNode.cs +++ b/Source/MonoGame.Extended/SceneGraphs/SceneNode.cs @@ -39,23 +39,26 @@ namespace MonoGame.Extended.SceneGraphs public SceneEntityCollection Entities { get; } public object Tag { get; set; } - public RectangleF GetBoundingRectangle() + public RectangleF BoundingRectangle { - var rectangles = Entities - .Select(e => - { - var r = e.GetBoundingRectangle(); - r.Offset(WorldPosition); - return r; - }) - .Concat(Children.Select(i => i.GetBoundingRectangle())) - .ToArray(); - var x0 = rectangles.Min(r => r.Left); - var y0 = rectangles.Min(r => r.Top); - var x1 = rectangles.Max(r => r.Right); - var y1 = rectangles.Max(r => r.Bottom); - - return new RectangleF(x0, y0, x1 - x0, y1 - y0); + get + { + var rectangles = Entities + .Select(e => + { + var r = e.BoundingRectangle; + r.Offset(WorldPosition); + return r; + }) + .Concat(Children.Select(i => i.BoundingRectangle)) + .ToArray(); + var x0 = rectangles.Min(r => r.Left); + var y0 = rectangles.Min(r => r.Top); + var x1 = rectangles.Max(r => r.Right); + var y1 = rectangles.Max(r => r.Bottom); + + return new RectangleF(x0, y0, x1 - x0, y1 - y0); + } } public void Draw(SpriteBatch spriteBatch) diff --git a/Source/MonoGame.Extended/Shapes/CircleF.cs b/Source/MonoGame.Extended/Shapes/CircleF.cs index 45a923db..4048c8d9 100644 --- a/Source/MonoGame.Extended/Shapes/CircleF.cs +++ b/Source/MonoGame.Extended/Shapes/CircleF.cs @@ -125,14 +125,16 @@ namespace MonoGame.Extended.Shapes } - public RectangleF GetBoundingRectangle() + public RectangleF BoundingRectangle { - var minX = Left; - var minY = Top; - var maxX = Right; - var maxY = Bottom; - - return new RectangleF(minX, minY, maxX - minX, maxY - minY); + get + { + var minX = Left; + var minY = Top; + var maxX = Right; + var maxY = Bottom; + return new RectangleF(minX, minY, maxX - minX, maxY - minY); + } } /// diff --git a/Source/MonoGame.Extended/Shapes/PolygonF.cs b/Source/MonoGame.Extended/Shapes/PolygonF.cs index 9ee924e6..6da80c01 100644 --- a/Source/MonoGame.Extended/Shapes/PolygonF.cs +++ b/Source/MonoGame.Extended/Shapes/PolygonF.cs @@ -96,14 +96,16 @@ namespace MonoGame.Extended.Shapes return new PolygonF(polygon.Vertices); } - public RectangleF GetBoundingRectangle() + public RectangleF BoundingRectangle { - var minX = Left; - var minY = Top; - var maxX = Right; - var maxY = Bottom; - - return new RectangleF(minX, minY, maxX - minX, maxY - minY); + get + { + var minX = Left; + var minY = Top; + var maxX = Right; + var maxY = Bottom; + return new RectangleF(minX, minY, maxX - minX, maxY - minY); + } } public bool Contains(Vector2 point) diff --git a/Source/MonoGame.Extended/Shapes/RectangleF.cs b/Source/MonoGame.Extended/Shapes/RectangleF.cs index 180287ed..81be6502 100644 --- a/Source/MonoGame.Extended/Shapes/RectangleF.cs +++ b/Source/MonoGame.Extended/Shapes/RectangleF.cs @@ -212,10 +212,7 @@ namespace MonoGame.Extended.Shapes return X <= x && x < X + Width && Y <= y && y < Y + Height; } - public RectangleF GetBoundingRectangle() - { - return this; - } + public RectangleF BoundingRectangle => this; /// /// Gets whether or not the provided coordinates lie within the bounds of this . diff --git a/Source/MonoGame.Extended/Shapes/ShapeF.cs b/Source/MonoGame.Extended/Shapes/ShapeF.cs index 7592cce1..55fb5f1f 100644 --- a/Source/MonoGame.Extended/Shapes/ShapeF.cs +++ b/Source/MonoGame.Extended/Shapes/ShapeF.cs @@ -8,9 +8,7 @@ namespace MonoGame.Extended.Shapes float Top { get; } float Right { get; } float Bottom { get; } - - RectangleF GetBoundingRectangle(); - + RectangleF BoundingRectangle { get; } bool Contains(float x, float y); bool Contains(Vector2 point); } diff --git a/Source/MonoGame.Extended/Sprites/Sprite.cs b/Source/MonoGame.Extended/Sprites/Sprite.cs index 3fc298e8..7de89391 100644 --- a/Source/MonoGame.Extended/Sprites/Sprite.cs +++ b/Source/MonoGame.Extended/Sprites/Sprite.cs @@ -61,12 +61,15 @@ namespace MonoGame.Extended.Sprites set { Origin = new Vector2(value.X * TextureRegion.Width, value.Y * TextureRegion.Height); } } - public RectangleF GetBoundingRectangle() + public RectangleF BoundingRectangle { - var corners = GetCorners(); - var min = new Vector2(corners.Min(i => i.X), corners.Min(i => i.Y)); - var max = new Vector2(corners.Max(i => i.X), corners.Max(i => i.Y)); - return new RectangleF(min.X, min.Y, (max.X - min.X), (max.Y - min.Y)); + get + { + var corners = GetCorners(); + var min = new Vector2(corners.Min(i => i.X), corners.Min(i => i.Y)); + var max = new Vector2(corners.Max(i => i.X), corners.Max(i => i.Y)); + return new RectangleF(min.X, min.Y, (max.X - min.X), (max.Y - min.Y)); + } } public Vector2[] GetCorners()