Sorry for all these questions, I really don't mean to bother you guys.
But the problem I'm having is that I don't know how to split the X
and Y
coordinates from the pygame get_pos
function, as get_pos
gets the X
and Y
coordinates in one.
Is there a way to split them into separate variables?
Thanks in advance
get_pos
returns a tuple. You can do a sequence unpacking:
x, y = pygame.mouse.get_pos()
To quote a great man (and Python documentation):
This is called, appropriately enough, sequence unpacking and works for any sequence on the right-hand side. Sequence unpacking requires the list of variables on the left to have the same number of elements as the length of the sequence. Note that multiple assignment is really just a combination of tuple packing and sequence unpacking
get_pos returns an array/tuple of two values
so you could do something like this:
X,Y = 0,1
p = pygame.mouse.get_pos()
mouse_pos = Vec2d(p[X],p[Y])
or even more simply
x,y = pygame.mouse.get_pos()
Also, this page has a button that lets you search for examples of the functions you're interested in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With