Pygame最简单的鼠标移动角色

import pygame
from pygame.locals import *

class Player(pygame.sprite.Sprite):
    
    def __init__(self,image):        
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load(image)
        self.rect = self.image.get_rect()
        self.screen = pygame.display.get_surface()
        
    def update(self):
        x,y = pygame.mouse.get_pos()
        self.rect.center = x,y
        
    def draw(self):
        self.screen.blit(self.image,self.rect)
        
if __name__ == "__main__":    
           
    pygame.init()

    screen = pygame.display.set_mode((600,600))
    pygame.display.set_caption("Pygame最简单的鼠标移动角色_lixingqiu")

    player = Player("character.png")

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == QUIT:
                running = False
        
        player.update()        
        screen.fill((0,0,0))
        player.draw()
        pygame.display.flip()

    pygame.quit()