我有一个球生成器,它“生成”并将球(圆)添加到模拟中。在
当球碰到列表s_boxes
中的静态多边形时,球将被移除。
这是由冲突处理程序ball_wall_collision
完成的。在
错误:
下面的弹出窗口按其名称显示的方式弹出
我的代码:
球形发生器
class BallGenerator:
def __init__(self, min_y, max_y, x):
self.min = min_y
self.max = max_y
self.x = x
self.counter = 0
def bowl(self, balls):
global ball_bowled
y = random.randint(self.min, self.max)
pos = to_pymunk((self.x,y))
r = 10
m = 15
i = pm.moment_for_circle(m, 0, r)
b = pm.Body(m,i)
b.position = pos
f_x = random.randint(-600000,-400000)
b.apply_force( (f_x,0.0),(0,0) )
ball = pm.Circle(b, r)
ball.elasticity = 0.75
ball.friction = 0.95
balls.append(ball)
space.add(ball,b)
print 'bowled'
ball_bowled += 1
def handle(self, balls):
if self.counter == FPS:
self.bowl(balls)
self.counter = 0
self.counter += 1
碰撞处理程序
^{pr2}$我在碰撞处理中做错了什么??在
space.remove
时遗漏了什么吗?在
问题似乎是在模拟步骤中,您试图从碰撞处理程序的空间中移除对象。在
相反,您可以尝试手动将所有球收集到一个列表中,然后在步骤之后调用remove,或者使用如下所示的post-step回调来排队除去:
(未测试代码)
我可能应该在API文档中使这一点更加明显。。我想知道是否应该将删除自动安排到步骤结束,或者使用不太具侵入性的选项,在python中触发断言,这样就不会得到c++错误。在
相关问题 更多 >
编程相关推荐