Pygame:如何将图像添加到矩形?

iAlex11

我正在Pygame上制作自己的游戏,我想将图像添加到矩形中,而不要使用彩色矩形。

我知道如何将图像添加到pygame的,但我想知道是否有一些方法来添加图像,并使用Pygame.rect属性,例如美国rect.centerYrect.centerX

有人知道吗?

r

加载图像,调用其get_rect方法以获取具有图像尺寸的rect,然后设置rect的坐标(有多个属性,例如x, y, topleft, center, etc.)...

IMAGE = pg.image.load('an_image.png').convert()  # or .convert_alpha()
# Create a rect with the size of the image.
rect = IMAGE.get_rect()
rect.center = (200, 300)

...,然后将rect作为dest参数传递pygame.Surface.blit给在rect.topleft坐标处取反图像

screen.blit(IMAGE, rect)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章