花栗鼠:如何删除尸体?
删除花栗鼠尸体的正确方法是什么?简单地调用 cpBodyFree 或 cpBodyDestroy 似乎不起作用,因为主体仍然显示在 cpSpaceEachBody 迭代中。
if(body->p.y < -260 || fabsf(body->p.x) > 340) {
/* body is permanently off the screen */
/* so it needs to be permanently deleted */
cpBodyFree(body); ??
cpBodyDestroy(body); ??
}
What's the right way to delete a Chipmunk body? Simply calling cpBodyFree
or cpBodyDestroy
doesn't seem to work, as the body still shows up in the cpSpaceEachBody
iteration.
if(body->p.y < -260 || fabsf(body->p.x) > 340) {
/* body is permanently off the screen */
/* so it needs to be permanently deleted */
cpBodyFree(body); ??
cpBodyDestroy(body); ??
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
删除主体的方法如下:
以下是如何让 Plink 演示降下一阵五边形并在以下情况下清理它们:
他们离开了屏幕。
将此行添加到“//添加大量五边形”循环中。这样我们就可以释放附着在身体上的形状。
从空间中移除形状和主体,然后释放形状和主体。事实并非如此
如果您首先删除/释放形状或首先删除主体,似乎很重要,只要您
请记住,当您释放主体时,您会丢失指向形状的指针。将 eachBody 函数更改为:
Here's how to delete a body:
Here's how to make the Plink demo rain down a single shower of pentagons and clean them up when
they go off screen.
Add this line to the "//Add lots of pentagons" loop. This is so we can free the shape attached to the body.
remove the shape and body from the space, then free the shape and body. It doesn't
seem to matter if you remove/free the shape first or the body first, so long as you
keep in mind that you lose the pointer to the shape when you free the body. Change the eachBody function to:
查看lib代码后,
调用
cpBodyFree< /code> (它在内部调用 cpBodyDestroy。
更新:除非您不需要验证和 cpfree(body) 调用;)
After looking in the lib code
Call
cpBodyFree
(it calls internally cpBodyDestroy internally.UPDATE: Except in cases where you don't need the validation and the
cpfree(body)
call ; )您必须确保形状是否已添加为静态,可能此代码会有所帮助:
you have to make sure whether the shape has been added as static or not, may be this code will help a bit: