I don't understand how it works. I don't know if I understood the purpose of this function wrong. I tried to search what posx=event.pos[0]
means but all I found was that if you want to take x
, write the code of posx,posy=pygame.mouse.get_pos()
and then take posx
. But I still can't understand the method he followed in the example I saw.
What does ''event.pos[0]'' mean in the pygame library? I saw an example using it to get the X axis of the cursor and ignore the Y axis
Asked Answered
See pygame.event
module. The MOUSEMOTION
, MOUSEBUTTONUP
and MOUSEBUTTONDOWN
events provide a position property pos
with the position of the mouse cursor. pos
is a tuple with 2 components, the x and y coordinate.
e.g.:
for event in pygame.event.get():
if event.type == pygame.MOUSEBUTTONDOWN:
print("mouse cursor x", event.pos[0])
print("mouse cursor y", event.pos[1])
pygame.mouse.get_pos()
returns a Tuple and event.pos
is a Tuple. Both give you the position of the mouse pointer as a tuple with 2 components:
ex, ey = event.pos
mx, my = pygame.mouse.get_pos()
pygame.mouse.getpos()
returns the current position of the mouse. The pos
attribute stores the position of the mouse when the event occurred. Note that you can call pygame.event.get()
much later than the event occurred. If you want to know the position of the mouse at the time of the event, you can call it up using the pos
attribute.
firstly, thanks I now understood that event.pos[] can take two parameters 0 or 1 (zero return x cursor and one for y cursor) but pygame.mouse.getpos() return (x,y) cursor together,right? –
Bellicose
© 2022 - 2024 — McMap. All rights reserved.