我有一个代码,可以使用pyBox2D和PyGame绘制由几个多边形组成的图形。我已经定义了实体和关节,可以很好地工作,可以完成预期的工作,但是当我想将头部从多边形更改为圆形时会出现问题,但是我无法绘制它,因为我用于绘制顶点,并且圆形具有没有顶点。
此部分代码(最终图形)中出现问题:
for body in world.bodies: #(ground_body, dynamic_body): # or: world.bodies
# The body gives us the position and angle of its shapes
for fixture in body.fixtures:
shape = fixture.shape
vertices = [(body.transform * v) * PPM for v in shape.vertices]
vertices = [(v[0], SCREEN_HEIGHT - v[1]) for v in vertices]
pygame.draw.polygon(screen, colors[body.type], vertices)
如上所述,问题在于box2D。 b2circleShape没有顶点。如何绘制圆形或广告顶点到该形状? 非常感谢
编辑:“重复项”没有回答我的问题,请您告诉我如何定义我尝试过的圆形物体
import Box2D # The main library
# Box2D.b2 maps Box2D.b2Vec2 to vec2 (and so on)
from Box2D.b2 import (world, polygonShape, staticBody, dynamicBody, circleShape)
from Box2D import (b2FixtureDef, b2PolygonShape, b2CircleShape)
chest_body = world.CreateDynamicBody(
position=(10, 6.5),
fixtures=b2FixtureDef(
shape=b2PolygonShape(box=(0.5, 1.5)), density=120),
angle=0) # This is a rectangular body which is defined correctly
circle = world.CreateDynamicBody(
position=(10, 6.5),
fixtures=b2FixtureDef(
shape=b2CircleShape(0.5),
angle=0)) # I tried this after checking your manual, this does not work
该问题可能是由于我不知道如何为pyBox2D运行IntelliSense或根本没有智能感知而引起的(可能是由于引起的)。这意味着我不知道需要哪些参数 任何帮助表示赞赏