基本上,我试图在Pygame中为两个图像创建一个矩形。但是当程序运行时,只有一个图像显示(橙子的)-我看不到蓝色的。我该如何解决这个问题?
class Button():
def __init__(self,x,y):
self.x = x
self.y = y
one_player_image = pygame.image.load('one_player.jpg').convert()
self.one_player_image = pygame.transform.scale(one_player_image,(50,50))
self.image_rect1 = self.one_player_image.get_rect()
self.image_rect1.center = (x,y)
two_player_image = pygame.image.load('two_player.jpg').convert()
self.two_player_image = pygame.transform.scale(two_player_image,(50,50))
self.image_rect2 = self.two_player_image.get_rect()
self.image_rect2.center = (x,y)
def draw_buttons(self):
WINDOW.blit(self.one_player_image,(self.image_rect1.x,self.image_rect1.y))
WINDOW.blit(self.two_player_image,(self.image_rect2.x,self.image_rect2.y))
one_player_button = Button(100,300)
two_player_button = Button(700,400)
1条答案
按热度按时间mu0hgdu01#
按钮class仅需具有1个矩形和1个图像:
但是,您需要创建该类的2个示例对象,每个按钮一个:
必须在应用程序循环中绘制这两个按钮: