[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] mouse.set_pos(mouse.get_pos())?



Hmm, answering my own question. I moved my call to pygame.events.get() to just before this (as opposed to just after it), and it works much better (though still a bit choppy). My mouse motion was all happening between the call to get() and the call to get_pos() so it wasn't getting reflected in the state.

--Mike

Michael George wrote:
Hello,

I'm trying to make a animation which may involve moving the window around, but I want to keep the mouse in the same "virtual" place. I've got the following snippet:

       xoff = (xres - xpos) / 2
       yoff = (yres - ypos) / 2
       x, y = pygame.mouse.get_pos()
       x    += xoff; y    += yoff
       xpos += xoff; ypos += yoff
       pygame.mouse.set_pos((x,y))

I expected this to move the mouse along with the animation (which it does), but it also keeps the mouse pegged at it's original position. In other words, when I move the mouse it springs immediately back to where it was - get_pos() doesn't seem to reflect the fact that the mouse has moved. If I remove the call to set_pos and print the value of get_pos then it changes, but if I add the call to set_pos back in, the value stays fixed when xoff = yoff = 0

Any thoughts?

--Mike