why when I put the second argument of the blit() method with surf.get_rect() the image becomes in the upper left corner of the screen? When I change the integer value it remains at the top left corner of the screen ... but when I replace the argument with (SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) it changes place to almost in the middle of the screen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import pygame from pygame. locals import ( K_UP, K_DOWN, K_LEFT, K_RIGHT, K_ESCAPE, KEYDOWN, QUIT, ) SCREEN_WIDTH = 800 SCREEN_HEIGHT = 600 class Player(pygame.sprite.Sprite): def __init__( self ): super ().__init__() self .surf = pygame.Surface(( 75 , 25 )) self .surf.fill(( 255 , 255 , 255 )) self .rect = self .surf.get_rect() pygame.init() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) player = Player() running = True while running: for event in pygame.event.get(): if event. type = = KEYDOWN: if event.key = = K_ESCAPE: running = False elif event. type = = QUIT: running = False screen.fill(( 0 , 0 , 0 )) screen.blit(player.surf, (SCREEN_WIDTH / 2 , SCREEN_HEIGHT / 2 )) pygame.display.flip() pygame.quit() |