0

I am using python 2.7, I would like to know if there is a way to centre an image in pygame. I have set the screen to fullscreen, is this possible? If it helps i will attach the code, thanks. import 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)
Dominic Wearne
  • 13
  • 1
  • 1
  • 5

2 Answers2

6

Yeah, it's possible. You have to create a rect object of the image:

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

And then:

rect.center = ("coordinates of center")
Giorgio B
  • 193
  • 6
-1

This StackOverflow question might be able to help you.

Pygame Image position

Basically though, you'd get the image rectangle. From there there are a lot of useful functions you can call to position it.

Community
  • 1
  • 1
Roy
  • 39
  • 7