如何将图像闪烁到特定的矩形上?
我是Pygame的初学者,尝试将图像爆炸到特定的矩形上很难。
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上,但是我希望图像在内部 而不是上方/下方。
任何帮助将不胜感激!
I'm a beginner in Pygame and I'm having trouble trying to blit an image onto specific 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))
I want to blit an image inside both the top
and the bottom
rects. I know how to add an image onto Pygame, but I want the image to be inside the rects, instead of above/below them.
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参见使用pygame?图像。将图像加载
pygame.image.image.image.image.load()
获取图像的边界矩形。创建一个
pygame.Rect
将边界矩形的中心通过障碍矩形的中心设置为blit
屏幕上的图像:See What is a good way to draw images using pygame?. Load the image with
pygame.image.load()
Get the bounding rectangle of the image. Create a
pygame.Rect
for the obstacle. Set the center of the bounding rectangle through the center of the obstacle rectangle and use it toblit
the image on the screen: