我有一個球發生器,它「生成」並將球(圓圈)添加到模擬中。pymunk space.remove方法的錯誤
當球在列表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
碰撞處理器
def ball_wall_collision(space, arb, balls, s_boxes):
shapes = arb.shapes
boxes = [box[0] for box in s_boxes] # Get walls
ball = None
wall = None
for ba in balls:
if ba in shapes:
ball = ba
break
for box in boxes:
if box in shapes:
wall = box
break
if wall and ball:
print 'removing'
space.remove(ball, ball.body) # Where the runtime problem happens
balls.remove(ball)
print 'removed'
return False
else:
return True
space.add_collision_handler(0,0,begin=ball_wall_collision,
balls=balls,s_boxes=s_boxes) # Other args to function
我在做什麼錯在碰撞處理?
- 我在致電
space.remove
的電話中缺少什麼嗎? - 功能不工作,因爲我想它? 或者是錯誤的其他地方(我不認爲這是)...
並且*錯誤*然後是什麼?請包括完整的追溯。 – 2013-03-07 10:28:38