I realize this is an old post, but I wanted to chime in with some things that I've found helpful.
Any time you have a sprite image that you're drawing to a rect, you can set the properties of the sprite's rect during the Surface.get_rect()
call.
For example, if we have a game object with attributes for its rect and its image, and we can reasonably assume that the image can be consistently centered around the object's rect.center
without making it display weirdly, the following is something I've found to be helpful.
for object in things_to_draw:
drawn_image = altered_image(object.image) # altered_image() is whatever changes you're making to the image before it's drawn
image_location = drawn_image.get_rect(center=object.rect.center) #returns the Surface's rect with rect.center set to the center of the object
myDisplay.blit(drawn_image, image_location)
Additionally, you may want to take a look at using the bounding_rect
of the image after doing a lot of work with said image. The bounding_rect
is the resized rect that a rotated image fits into; if your image is significantly taller than it is wide (or vice versa) this might be more useful for collision detection than a static rect that is set once. One can get this by using Surface.get_bounding_rect()
; however, for whatever reason this method cannot be passed the same setters as the previous one, so you'll have to set new values after this rect is created.
image_rect = object.image.get_bounding_rect() #does not take the same args! can't set rect.center until the next line...
image_rect.center = (some_x, some_y) #sets the bounding_rect's center to whatever X/Y you're using
Like I said, I know it's an older post, but this stuff was driving me up a wall at first as well.