From 97b9eb6c1b2d92a353068ad025cd910b6c87deef Mon Sep 17 00:00:00 2001 From: Gandifil Date: Fri, 1 Dec 2023 23:49:43 +0300 Subject: [PATCH] Add method for set default layer --- .../CollisionComponent.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/cs/MonoGame.Extended.Collisions/CollisionComponent.cs b/src/cs/MonoGame.Extended.Collisions/CollisionComponent.cs index 349acf8e..e89fa91f 100644 --- a/src/cs/MonoGame.Extended.Collisions/CollisionComponent.cs +++ b/src/cs/MonoGame.Extended.Collisions/CollisionComponent.cs @@ -32,9 +32,21 @@ namespace MonoGame.Extended.Collisions /// Boundary of the collision tree. public CollisionComponent(RectangleF boundary) { - var layer = new Layer(new QuadTreeSpace(boundary)); + SetDefaultLayer(new Layer(new QuadTreeSpace(boundary))); + } + + /// + /// The main layer has the name from . + /// The main layer collision with itself and all other layers. + /// + /// Layer to set default + public void SetDefaultLayer(Layer layer) + { + if (_layers.ContainsKey(DEFAULT_LAYER_NAME)) + Remove(DEFAULT_LAYER_NAME); Add(DEFAULT_LAYER_NAME, layer); - AddCollisionBetweenLayer(layer, layer); + foreach (var otherLayer in _layers.Values) + AddCollisionBetweenLayer(layer, otherLayer); } ///