我不能让QueryAABB在PyBox2D里工作。我做错什么了?

2024-10-04 11:29:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图检测鼠标指针是否在一个物体上,以便我可以拖动它,但我得到下面的错误。我不知道是我还是pybox2d中的一个bug,但我已经做了几个小时了,而且这些文档都很古老

>>> from Box2D.b2 import *
>>> w = world()
>>> my_body = w.CreateDynamicBody(position=(1,1))
>>> aabb = AABB()
>>> aabb.lowerBound = (1-.001,1-.001)
>>> aabb.upperBound = (1+.001,1+.001)
>>> def callback(fixture):
...     shape = fixture.shape
...     p = (1,1)
...     if fixture.body.type != 0: # type 0 is static
...             if shape.TestPoint(fixture.body.transform,p):
...                     return False
...     return True
... 
>>> w.QueryAABB(callback,aabb)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: in method 'b2World_QueryAABB', argument 2 of type 'b2QueryCallback *'

显然,我希望查询返回True(没有检测到形状,请继续查找),因为我还没有为主体创建形状,但这并不能解释类型错误。请帮忙,提前谢谢


Tags: intruereturniftype错误callbackbody