跟随鼠标的 PyGlet 形状

PyGlet Shape Following The Mouse

所以我尝试用 PyGlet 制作一个“游戏”:

这是我的代码:

import pyglet
from pyglet import shapes

window = pyglet.window.Window(800, 600, "PyGlet Window")
circle = shapes.Circle(x = 100, y = 100, radius = 13, color=(255, 255, 255))

def callback(dt):
    pass

pyglet.clock.schedule_interval(callback, 0.5)

@window.event
def on_draw():
    window.clear()
    circle.draw()

pyglet.app.run()

如何让圆跟随鼠标移动?谢谢!

实施 on_mouse_motion 事件(参见 Working with the mouse) and change the position of the shape (see pyglet.shapes):

@window.event
def on_mouse_motion(x, y, dx, dy):
    circle.x = x
    circle.y = y