简体   繁体   中英

How to get image position in Pygame

I am coding for a mouse drag and drop effect on images. Meanwhile, I want to take record of the upper-left point of image each time I dragged and dropped it, are there any ways to get it?

What methods are you using to draw the images? It's hard to answer this question without that.

If you aren't already doing this, you could use a class to hold data about your image, such as position and geometry.

If you derive your classes from pygame.sprite.Sprite , you can get the position by guy.rect . Depending on if you want center, or toplef, or the full rect:

guy.rect.topleft or guy.rect.center or guy.rect

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM