我已经尝试了很多,但仍然不明白为什么它不加载按钮。
import pygame
pygame.init()
screen = pygame.display.set_mode((3840,2160))
running = True
mouse = pygame.mouse.get_pos()
pygame.display.set_caption("GermanBall")
bg = pygame.image.load("Tan.jpg")
icon = pygame.image.load("box.png")
button1 = pygame.image.load("shirt.png").convert_alpha()
class Button():
def __init__(self,x,y,image):
self.image = image
self.rect = self.image.get_rect()
self.rect.topleft = (x,y)
def draw(self):
screen.blit(self.image,(self.rect.x,self.rect.y))
start = Button(0,0,button1)
pygame.display.set_icon(icon)
while running == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
start.draw()
screen.blit(bg,(0,0))
pygame.display.update()
我想要加载按钮。它不会给我错误,只是无法加载。
最佳答案
您必须在 screen.blit(bg,(0,0))
之后、pygame.display.update 之前调用
。注意:start.draw()
()screen.blit(bg, (0,0)
在整个屏幕上绘制背景图像,这样之前绘制的所有内容都会被 overdraw 。pygame.display.update()
更新显示并使显示表面的所有更改立即可见:
while running == True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# draw background
screen.blit(bg,(0,0))
# draw button
start.draw()
# update display
pygame.display.update()
关于python - 为什么这段代码没有绘制我想要的开始按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75074144/