And of course if you don't subclass Window, there is also the nice
decorators for window events, as you probably already know:
mouse_pos = 0, 0
@window.event
def on_mouse_motion(x, y, dx, dy):
mouse_pos = x, y
Keep in mind that changing the Sprite.position is a somewhat expensive
operation, because the Sprite's vertex list is re-calculated every time you
do. For this reason, it makes more sense to use an intermediate variable
(like mouse_pos above), and update the Sprite's position once every update
of your application.
On Tuesday, June 21, 2016 at 7:06:36 AM UTC+9, Paulo Martins wrote:
>
> Hi,
>
> Imagine that I am in a "update(dt)" function doing animation stuff, and
> need to position some sprite according to the mouse position: is there an
> easy way, like a function, to get the current mouse position (x, y
> coordinates)?
> Or the only way is to creat something like a global variable x and y and
> keep track/registe the mouse x, y inside the on_mouse_motion event each
> time it moves, since the start of the app?
>
> I am tired and sleepy, working in a hurry because of deadlines, searched
> but can't find an easy way - sorry if this question is stupid and has an
> obvious answer I am not seeing in this moment.
>
> Thanks, all the best
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.