我正在使用python 2.7,我想知道是否有办法在pygame中居中图像。我已将屏幕设置为全屏,这可能吗?如果它有助于我附上代码,谢谢。 导入pygame import os
_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)
答案 0 :(得分:1)
image = "insert image"
rect = image.get_rect ()
然后:
rect.center = ("coordinates of center")
答案 1 :(得分:0)