Вам нужно определить тип события, например MOUSEBUTTONDOWN, MOUSEBUTTONUP, MOUSEMOTION
.
Когда вы обнаружили движение мыши, проверьте, щелкнуло ли оно с помощью атрибута event.buttons
.
Вот мой инструмент:
import pygame
from pygame.locals import *
pygame.display.init()
screen = pygame.display.set_mode((800, 600))
img = pygame.image.load('sky.png')
imgPos = pygame.Rect((0, 0), (0, 0))
LeftButton = 0
while 1:
for e in pygame.event.get():
if e.type == QUIT: exit(0)
if e.type == MOUSEMOTION:
if e.buttons[LeftButton]:
# clicked and moving
rel = e.rel
imgPos.x += rel[0]
imgPos.y += rel[1]
screen.fill(0)
screen.blit(img, imgPos)
pygame.display.flip()
pygame.time.delay(30)
Возможно, вам потребуется прочитать: Документ о событии Pygame