2016-05-24 19 views
0

私はpython 2.7を使用していますが、pygameに画像を中央に配置する方法があるかどうかを知りたいと思います。私は画面をフルスクリーンに設定しましたが、これは可能ですか?それが私のコードを添付します、おかげで助けてくれてありがとう。 インポート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) 

答えて

0

はい、可能です。その後、

image = "insert image" 
rect = image.get_rect() 

そして: あなたは画像の矩形オブジェクトを作成する必要が

rect.center = ("coordinates of center") 
0

このStackOverflowの質問 インポートOSはあなたを助けることができるかもしれません。

Pygame Image position

は基本的に、しかし、あなたは画像の矩形を取得したいです。そこには、それを配置するために呼び出すことができる多くの便利な関数があります。

+0

だから私はsw.pngでspace_ship_rectを交換しなければならない - これは私のコードに行くのですか? –