How do I rotate an image around its center using Pygame?

后端 未结 6 1521
[愿得一人]
[愿得一人] 2020-11-22 00:13

I had been trying to rotate an image around its center in using pygame.transform.rotate() but it\'s not working. Specifically the part that hangs is rot_i

6条回答
  •  猫巷女王i
    2020-11-22 01:09

    Everything you need for drawing an image in pygame

    game_display = pygame.display.set_mode((800, 600))
    
    x = 0
    y = 0
    angle = 0
    
    img = pygame.image.load("resources/image.png")
    img = pygame.transform.scale(img, (50, 50)) # image size
    
    def draw_img(self, image, x, y, angle):
        rotated_image = pygame.transform.rotate(image, angle) 
        game_display.blit(rotated_image, rotated_image.get_rect(center=image.get_rect(topleft=(x, y)).center).topleft)
    
    # run this method with your loop
    def tick():
        draw_img(img, x, y, angle)
    

提交回复
热议问题