pygame
怎样改才能让鼠标控制图片移动?
import pygame as pg
import sys
import time
pg.init() #初始化
screen = pg.display.set_mode((400, 400))
pg.display.set_caption("Pygame窗口")
image= pg.image.load("u=4269708609,317730862&fm=253&fmt=auto&app=138&f=JPEG.png")
image = pg.transform.scale(image,(25,25))
clock = pg.time.Clock()#控制FPS
background_color = (255, 255, 255)
while True:
screen.fill((background_color))
screen.blit(image, (0, 0))
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
sys.exit(0)
elif event.type == pg.MOUSEBUTTONDOWN:
if event.button == 1:
x, y = pg.mouse.get_pos()
x-= image.get_width() / 2
y-= image.get_height() / 2
screen.blit(image, (x, y))
clock.tick(65)
pg.display.flip()