[英]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.