我是pygame的新手,我正在编写一个程序,允许用户在pygame窗口周围单击并拖动一个矩形,然后通过套接字发送它的坐标.我可以在鼠标点击时移动矩形,但我已经搞乱了一段时间,仍然无法弄清楚如何实现点击和拖动.任何帮助,将不胜感激.这是相关的代码:
from pygame.locals import *
import socket, pygame, time
#define variables
x = y = 0
screen = pygame.display.set_mode((430, 410))
targetRectangle = pygame.draw.rect(screen, (255, 0, 0), (176, 134, 7, 7))
pygame.display.flip()
#define smaller functions
#define function to start pygame window
def startPygame():
pygame.display.set_caption(option + " Tracking System")
pygame.mouse.set_visible(True)
screen.fill((255, 255, 255))
targetRectangle = pygame.draw.rect(screen, (255, 0, 0), (176, 134, 7, 7))
pygame.display.flip()
#define function to update pygame window
def updateWindow():
screen.fill((255, 255, 255))
global targetRectangle
global xPosition
global yPosition
targetRectangle …Run Code Online (Sandbox Code Playgroud)