pygame 不会在我的 pymunk 模拟中画圆圈

pygame wont draw my circle in my pymunk simulation

我是 pymunk 的新手,我想为我未来的游戏制作物理引擎,这只是一个小问题,我的代码无法绘制 pygame 试图可视化的圆圈。这是我的代码。

import pygame
import pymunk
import sys


def create_item(space):
    body = pymunk.Body(1, 100, body_type = pymunk.Body.DYNAMIC)
    body.position = (450, 50)
    shape = pymunk.Circle(body, 80)
    space.add(body, shape)
    return shape


def draw_items(items):
    for item in items:
        pygame.draw.circle(screen, item_color, item.body.position, 80)


def quit():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()


def display_update():
    screen.fill(bg_color)
    clock.tick(FPS)
    space.step(1/60)
    pygame.display.flip()


# Constructor
pygame.init()

# Constants and Variables
WIDTH = 900
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
FPS = 60
clock = pygame.time.Clock()

# Colors
bg_color = 30, 30, 40
item_color = 200, 200, 200

# Pymunk Variables
space = pymunk.Space()
space.gravity = (0, 500)
items = []
items.append(create_item(space))


# Loops
def main():
    running = True
    while running:
        quit()
        display_update()
        draw_items(items)


main()

我真的不知道这里的问题是什么,它没有给我错误或类似的东西,我只得到一个干净的空白 canvas 我的 bg 颜色。(也很抱歉差评)

您必须在更新显示之前绘制对象

def main():
    running = True
    while running:
        quit()
        screen.fill(bg_color)
        draw_items(items)
        pygame.display.flip()
        clock.tick(FPS)
        space.step(1/60)

您实际上是在 Surface object. If you draw on the Surface associated to the PyGame display, this is not immediately visible in the display. The changes become visibel, when the display is updated with either pygame.display.update() or pygame.display.flip() 上绘图。

典型的 PyGame 应用程序循环必须: