Con remocion del World de simulacion

This commit is contained in:
Miguel 2024-05-18 15:39:46 +02:00
parent 9cf86d001e
commit 2e8c3b7d83
1 changed files with 26 additions and 10 deletions

View File

@ -42,13 +42,16 @@ namespace CtrEditor.Simulacion
_radius = diameter / 2;
Create(Body.Position); // Recrear el círculo con el nuevo tamaño
}
public void Create(Vector2 position)
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body);
}
}
public void Create(Vector2 position)
{
RemoverBody();
Body = BodyFactory.CreateCircle(_world, _radius, 1f, position);
Body.FixtureList[0].IsSensor = true;
@ -92,13 +95,16 @@ namespace CtrEditor.Simulacion
var newShape = new PolygonShape(PolygonTools.CreateRectangle(width / 2, height / 2), 1f);
Body.CreateFixture(newShape);
}
public void Create(float width, float height, Vector2 position, float angle = 0)
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body);
}
}
public void Create(float width, float height, Vector2 position, float angle = 0)
{
RemoverBody();
Body = BodyFactory.CreateRectangle(_world, width, height, 1f, position);
Body.FixtureList[0].IsSensor = true;
Body.BodyType = BodyType.Static;
@ -117,13 +123,16 @@ namespace CtrEditor.Simulacion
_world = world;
Create(start, end);
}
public void Create(Vector2 start, Vector2 end)
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body); // Elimina el cuerpo anterior si existe
_world.RemoveBody(Body);
}
}
public void Create(Vector2 start, Vector2 end)
{
RemoverBody();
Body = BodyFactory.CreateEdge(_world, start, end);
Body.BodyType = BodyType.Static;
Body.UserData = this; // Importante para la identificación durante la colisión
@ -178,13 +187,16 @@ namespace CtrEditor.Simulacion
}
set { _mass = value; }
}
private void Create(Vector2 position)
public void RemoverBody()
{
if (Body != null)
{
_world.RemoveBody(Body); // Remover el cuerpo anterior si existe
_world.RemoveBody(Body);
}
}
private void Create(Vector2 position)
{
RemoverBody();
Body = BodyFactory.CreateCircle(_world, _radius, 1f, position);
Body.BodyType = BodyType.Dynamic;
@ -321,15 +333,19 @@ namespace CtrEditor.Simulacion
switch (Objeto)
{
case simBotella obj:
obj.RemoverBody();
circles.Remove(obj);
break;
case simTransporte obj:
obj.RemoverBody();
rectangles.Remove(obj);
break;
case simGuia obj:
obj.RemoverBody();
lines.Remove(obj);
break;
case simDescarte obj:
obj.RemoverBody();
descartes.Remove(obj);
break;
default: