Disposable Rigidbody2D

This commit is contained in:
Simon Lübeß
2023-10-28 21:48:56 +02:00
parent 38fc1f63b3
commit b41eaad788
@@ -375,7 +375,7 @@ namespace GlitchyEngine.World
public SceneLight SceneLight; public SceneLight SceneLight;
} }
struct Rigidbody2DComponent struct Rigidbody2DComponent : IDisposableComponent
{ {
public enum BodyType { Static = 0, Dynamic = 1, Kinematic = 2 } public enum BodyType { Static = 0, Dynamic = 1, Kinematic = 2 }
@@ -497,6 +497,12 @@ namespace GlitchyEngine.World
if (RuntimeBody != null) if (RuntimeBody != null)
Box2D.Body.SetAngularVelocity(RuntimeBody, velocity); Box2D.Body.SetAngularVelocity(RuntimeBody, velocity);
} }
public void Dispose()
{
if (RuntimeBody != null && ScriptEngine.Context?.[Friend]_physicsWorld2D != null)
Box2D.World.DestroyBody(ScriptEngine.Context.[Friend]_physicsWorld2D, RuntimeBody);
}
} }
/*struct InternalBug /*struct InternalBug