我正在Pygame上制作自己的游戏,我想将图像添加到矩形中,而不要使用彩色矩形。
我知道如何将图像添加到pygame的,但我想知道是否有一些方法来添加图像,并使用Pygame.rect属性,例如美国rect.centerY
和rect.centerX
。
有人知道吗?
加载图像,调用其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] 删除。
我来说两句