无法摧毁身体(Box2d)
- for (var bb1:b2Body= world.GetBodyList(); bb1; bb1 = bb1.GetNext())
{
if (bb1.GetUserData() is Sprite)
{
world.DestroyBody(bb1);
}
}
world=null;
删除box2d中的b2body是否正确?
但我仍然看到舞台上的物体。
- for (var bb1:b2Body= world.GetBodyList(); bb1; bb1 = bb1.GetNext())
{
if (bb1.GetUserData() is Sprite)
{
world.DestroyBody(bb1);
}
}
world=null;
is it correct to remove the b2body in box2d?
but still i'm seeing the objects in stage.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您尝试在世界的 Step() 函数中执行此操作(例如在接触侦听器中),它将不起作用,因为世界仍在处理实体。您需要记下要摧毁的物体,然后在世界时间步结束后摧毁它们。
另外,我不确定你使用的是什么语言,但这个循环会破坏一个主体,然后对你刚刚破坏的东西调用 GetNext() ,这似乎有点奇怪。
If you are trying to do this inside the world's Step() function (eg in a contact listener), it will not work because the world is still processing the bodies. You will need to make a note of which bodies you want to destroy, and then destroy them after the world's time step has finished.
Also, I'm not sure what language you are using but it seems a little strange that this loop will destroy a body and then call GetNext() on the thing you just destroyed.
Box2D AS3 端口有 bug,与 DestroyBody 函数连接。
错误修复位于此处(俄语)。
问题出在联系池中。
并且您必须在您的世界时间步结束后移除物体。
Box2D AS3 port has bugs, connected with DestroyBody function.
Bug fix is here(in Russian).
Trouble is in contact pool.
And you must remove bodies after your world's timestep has finished.