reset password
Author Message
disrael
Posts: 44
Posted 19:11 May 04, 2015 |

I was wondering if anyone knew of a way to use pygame.mouse.get_pos and pull just the x value or y value from it?

NoCool14
Posts: 2
Posted 19:16 May 04, 2015 |

hey so the

pygame.mouse.get_pos()

function returns a tuple so what you can do is

position = pygame.mouse.get_pos()

and then position[0] will get you the x coordinate and position[1] will return the y coordinate of the current mouse position

Hope that was what you were asking.

jwarren6
Posts: 56
Posted 19:16 May 04, 2015 |

How about:

    def update(self):
        # Get the current mouse position. This returns the position as a list of two numbers.
        pos = pygame.mouse.get_pos()
 
        # Set the player x position to the mouse x position
        self.rect.x = pos[0]

        # Set the player y position to the mouse y position
        self.rect.y = pos[1]

Last edited by jwarren6 at 19:18 May 04, 2015.
disrael
Posts: 44
Posted 19:17 May 04, 2015 |

Ah, thank you so much. I was thinking there might be a build in method to find x and y, but couldn't find it.

Thank you again.