我的pymunk程序太慢了。每次我运行程序时,加载时间都是5秒。这是我的密码。提前谢谢。
import pymunk # Import pymunk..
import pygame
pygame.init()
display = pygame.display.set_mode((800,800))
clock = pygame.time.Clock()
space = pymunk.Space() # Create a Space which contain the simulation
FPS = 30
def convert_coordinates(point):
return point[0], 800-point[1]
running = True
space.gravity = 0,-1000 # Set its gravity
# Set the position of the body
body = pymunk.Body()
shape = pymunk.Circle(body, 10)
body.position = (400,800)
shape.density = 1
space.add(body,shape)
while running: # Infinite loop simulation
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.display.update()
clock.tick(FPS)
space.step(1/FPS)
display.fill((255,255,255))
x,y = convert_coordinates(body.position)
sprite = pygame.draw.circle(display,(255,0,0), (int(x),int(y)),10)
pygame.quit()发布于 2020-11-19 16:42:18
这是压痕的事。您必须在应用程序循环而不是事件循环中绘制场景:
while running: # Infinite loop simulation
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# <--- INDENTATION
clock.tick(FPS)
space.step(1/FPS)
display.fill((255,255,255))
x,y = convert_coordinates(body.position)
sprite = pygame.draw.circle(display,(255,0,0), (int(x),int(y)),10)
pygame.display.update()
pygame.quit()https://stackoverflow.com/questions/64916069
复制相似问题