Quick answer: Pygame Rect objects assigned to multiple variables sharing state? Rects are mutable; a = b shares the reference, and a.inflate_ip changes b too.
A camera saves the player rect as view_rect = player.rect and inflates by 100 for a buffer. The player’s actual hitbox also inflates because they’re the same object.
Reference Semantics
Python (and Pygame) Rects are objects. Assignment binds the same object to a new name. Mutations through either name see each other.
Copy Explicitly
view_rect = player.rect.copy()
view_rect.inflate_ip(100, 100)copy() creates an independent Rect. Mutating it doesn’t touch player.rect.
Non-_ip vs _ip
inflate returns a new Rect; inflate_ip mutates in place. Use non-_ip when you want a derived value without changing the source.
Pass to Functions Carefully
Passing a Rect to a function that calls _ip methods mutates the caller’s rect. Document such APIs or always copy first.
Verifying
Inflated view rects don’t change source rects. Each variable holds an independent value as expected.
“Rects are mutable references. copy() for independence; _ip methods change in place.”
Prefer the non-_ip variants by default — clearer intent and you only see in-place mutations when you actually need them.