我该如何减慢速度?现在它立即向下/向左/向上/向右。我知道它与时间模块有关,但我不知道如何实现它。基本上我想把这个过程从 10 年减慢到 490 年。不要添加延迟,而是减慢过程,就像让它慢动作一样。我什至尝试了 120fps 的 pygame 时钟,但它不起作用
import time
import pygame
from pygame.locals import *
clock = pygame.time.Clock()
fps = 120
pygame.init()
surface = pygame.display.set_mode((600, 600))
background = pygame.image.load('back.png')
surface.blit(background, (0, 0))
block = pygame.image.load('block.png').convert()
block_y = 0
block_x = 0
surface.blit(block, (block_x, block_y))
def draw():
surface.blit(background, (0, 0))
surface.blit(block, (block_x, block_y))
pygame.display.flip()
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
running = False
if event.key == K_UP:
block_y -= 10
draw()
if event.key == K_DOWN:
block_y += 10
draw()
if event.key == K_LEFT:
block_x -= 10
draw()
if event.key == K_RIGHT:
block_x += 10
draw()
elif event.type == QUIT:
running = False
elif event.type == KEYUP:
clock.tick(fps)
if event.key == K_UP:
block_y -= 10
draw()
if event.key == K_DOWN:
block_y += 490
draw()
if event.key == K_LEFT:
block_x -= 100
draw()
if event.key == K_RIGHT:
block_x += 510
draw()
```