So I try to make a "game" with PyGlet:
This is my code:
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()
How to make the circle follow the mouse? Thanks!
Implement the on_mouse_motion
event (see 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.