gpt4 book ai didi

python - Pygame 无响应显示

转载 作者:行者123 更新时间:2023-12-04 09:02:06 24 4
gpt4 key购买 nike

因此,我正在尝试使用 Sprite 创建具有 X 和 Y 运动的基本 2D python 游戏的基础。

然而,尽管此处的代码尝试 screen.fillscreen.blit

,但显示没有响应
playerX = 50
playerY = 50
player = pygame.image.load("player.png")
width, height = 64*8, 64*8
screen=pygame.display.set_mode((width, height))
screen.fill((255,255,255))
screen.blit(player, (playerX, playerY))

我是不是漏掉了什么重要的东西?

最佳答案

一个最小的典型 PyGame 应用程序

参见 pygame.event.get() :

For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.

另见 Python Pygame Introduction

最小示例: repl.it/@Rabbid76/PyGame-MinimalApplicationLoop

import pygame

pygame.init()

playerX = 50
playerY = 50
player = pygame.image.load("player.png")
width, height = 64*8, 64*8
screen = pygame.display.set_mode((width, height))

# main application loop
run = True
while run:

# event loop
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False

# clear the display
screen.fill((255,255,255))

# draw the scene
screen.blit(player, (playerX, playerY))

# update the display
pygame.display.flip()

关于python - Pygame 无响应显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63540062/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com