即使我将时钟刻度设置为 60 并且它在正确的空间中,我也没有得到任何帧。我也知道它不是我的电脑,因为我运行过帧数更好的大型游戏。它也不能是缩进,因为我的意图是正确的。
import pygame
pygame.init()
screen = pygame.display.set_mode((500, 500))
gameclock = pygame.time.Clock()
fps = str(int(gameclock.get_fps()))
playerX = 250
playerY = 250
playerSpeed = 3
playerFrontImg = pygame.image.load("Images/PlayerImages/playerFront.png")
playerRightImg = pygame.image.load("Images/PlayerImages/playerRight.png")
playerBackImg = pygame.image.load("Images/PlayerImages/playerBack.png")
playerLeftImg = pygame.transform.flip(playerRightImg, True, False)
playercurrentImg = playerFrontImg
running = True
while running:
gameclock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_UP:
playerY -= playerSpeed
playercurrentImg = playerBackImg
if event.key == pygame.K_DOWN:
playerY += playerSpeed
playercurrentImg = playerFrontImg
if event.key == pygame.K_RIGHT:
playerX += playerSpeed
playercurrentImg = playerRightImg
if event.key == pygame.K_LEFT:
playerX -= playerSpeed
playercurrentImg = playerLeftImg
if event.type == pygame.KEYUP:
if event.key == pygame.K_UP:
playerY += 0
if event.key == pygame.K_DOWN:
playerY += 0
if event.key == pygame.K_RIGHT:
playerX += 0
if event.key == pygame.K_LEFT:
playerX += 0
playerRect = playercurrentImg.get_rect(topleft = (playerX, playerY))
screen.fill((255, 255, 100))
print(fps)
screen.blit(playercurrentImg, (playerX, playerY))
pygame.display.update()
pygame.quit()
quit()
任何帮助将不胜感激,我一直在努力解决这个问题。关于我应该如何组织我的代码还有其他提示吗?