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