我正在尝试将精灵图像插入 pygame 窗口,但它不会弹出
(我跟着yt tut所以idk)我的代码:idk如果我把代码放在错误的地方
import pygame
white = (255,255,255)
black = (0,0,0)
orange = (255,165,0)
player_sprite = pygame.image.load("will smith.png") .convert_alpha
pygame.init()
display = pygame.display.set_mode((850,850))
pygame.display.set_caption('Conners Game')
exit = False
while not exit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit = True
print(event)
display.fill(white)
pygame.display.update()
pygame.quit()
quit()
不太确定为什么这样做,我是python新手所以idk
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有多种需要修复的事情。首先,您实际上需要 blit 屏幕上的图像。
.convert_alpha()
是一种方法,在初始化pygame并设置视频模式后,您需要调用它。您可以阅读有关
convert_alpha()
在这里这是最终的工作代码
There are multiple things that needs to fixed. First of all to you actually need to blit the image on the screen.
.convert_alpha()
is a method and you need to call it after you initialize pygame and set the video mode.You can read more about
convert_alpha()
hereHere's the final working code
您必须 >应用程序循环中的映像,清除显示后,然后更新显示器之前:
convert_alpha
是功能。您错过了括号player_sprite = pygame.image.load(“ will smith.png”)。convert_alpha
,您在初始化pygame之前也无法调用pygame函数。
pygame.init()
应该是第一个调用的pygame函数。完整示例:
典型的PyGame应用程序循环必须:
pygame.time.clock.tick
pygame.event.pump()
或pygame.event.get()
。BLIT
所有对象)You have to
blit
the image in the application loop, after clearing the display and before updating the display:convert_alpha
is function. You missed the parenthesesplayer_sprite = pygame.image.load("will smith.png").convert_alpha
Also, you cannot call a pygame function before you initialize pygame.
pygame.init()
should be the very first pygame function called.Complete example:
The typical PyGame application loop has to:
pygame.time.Clock.tick
pygame.event.pump()
orpygame.event.get()
.blit
all the objects)pygame.display.update()
orpygame.display.flip()