Files
MonoGame.Extended/Source/MonoGame.Extended.SceneGraphs/SceneGraph.cs
T
Lucas Girouard-Stranks a1f8566a46 Geometric Primitives Cleanup (#346)
* CircleF and RectangleF

* Fix build errors
2017-03-12 20:32:07 +10:00

43 lines
1.0 KiB
C#

using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace MonoGame.Extended.SceneGraphs
{
public class SceneGraph
{
public SceneGraph()
{
RootNode = new SceneNode();
}
public SceneNode RootNode { get; }
public void Draw(SpriteBatch spriteBatch)
{
RootNode?.Draw(spriteBatch);
}
public SceneNode GetSceneNodeAt(float x, float y)
{
var node = RootNode;
while ((node != null) && node.BoundingRectangle.Contains(new Point2(x, y)))
{
var childNode = node.Children.FirstOrDefault(c => c.BoundingRectangle.Contains(new Point2(x, y)));
if (childNode != null)
node = childNode;
else
return node;
}
return null;
}
public SceneNode GetSceneNodeAt(Vector2 position)
{
return GetSceneNodeAt(position.X, position.Y);
}
}
}