我是一个游戏初学者,我有困难,试图将图像模糊到特定的rects。
obstacle_width = 70
obstacle_height = random.randint(150, 450)
obstacle_colour = (211, 253, 117)
obstacle_x_change = -4
obstacle_x = 500
obstacle_gap = 170
def display_obstacle(height):
top = pygame.draw.rect(screen, obstacle_colour,
(obstacle_x, 0, obstacle_width, height))
bottom_obstacle_height = 635 - height - obstacle_gap
bottom = pygame.draw.rect(screen, obstacle_colour,
(obstacle_x, height + obstacle_gap, obstacle_width,
bottom_obstacle_height))
我想在top
和bottom
rects中创建一个图像。我知道如何将图像添加到Pygame中,但是我希望图像是在的rects中,而不是在上面/下面。
任何帮助都将不胜感激!
发布于 2022-04-24 17:30:01
见What is a good way to draw images using pygame?。用pygame.image.load()
加载图像
obstacle_image = pygame.image.load("obstacle.png")
获取图像的边框。为障碍物创建一个pygame.Rect
。通过障碍物矩形的中心设置边界矩形的中心,并使用它在屏幕上blit
图像:
obstacle_rect = pygame.Rect(obstacle_x, height + obstacle_gap, obstacle_width, bottom_obstacle_height)
image_rect = obstacle_image.get_rect(center = obstacle_rect.center)
screen.blit(obstacle_image, image_rect)
https://stackoverflow.com/questions/71990691
复制相似问题