[英]How to centre an image in pygame?
我正在使用python 2.7,我想知道是否有一种方法可以在pygame中居中放置图像。 我已将屏幕设置为全屏,这可能吗? 如果有帮助,我将附加代码,谢谢。 导入pygame导入操作系统
_image_library = {}
def get_image(path):
global _image_library
image = _image_library.get(path)
if image == None:
canonicalized_path = path.replace('/', os.sep).replace('\\', os.sep)
image = pygame.image.load(canonicalized_path)
_image_library[path] = image
return image
pygame.init()
screen = pygame.display.set_mode((0, 0))
done = False
clock = pygame.time.Clock()
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
screen.fill((0, 0, 0))
screen.blit(get_image('sw.png'), (0, 0)
pygame.display.flip()
clock.tick(60)
是的,有可能。 您必须创建图像的rect对象:
image = "insert image"
rect = image.get_rect ()
接着:
rect.center = ("coordinates of center")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.