I was just going through the .rect
method of pygame in the official docs.
We have 2 cases ,
pygame.rect.move(arg1,arg2)
which is used to move a .rect
object on the screen
and
pygame.rect.move_ip(arg1,arg2)
which is , according to the docs, also used to move a .rect
object
on the screen but it moves it in place
I didnt quite get what it means. Can anyone explain what move in place means?
move_ip changes the pygame. Rect object itself, rect. move does not change the object, but it returns a new object with the same size and "moved" position.
The method move(v) creates a new Rect which has moved by a vector v . The method move_ip(v) moves a Rect in place. The following program uses the 4 arrow keys to move a rectangle around. The thin blue rectangle is the orignal one, the thick red rectangle is the moved one.
Rect holds four integer coordinates for a rectangle. The rectangle is represented by the coordinates of its 4 edges (left, top, right bottom). These fields can be accessed directly. Use width() and height() to retrieve the rectangle's width and height.
Pygame uses Rect objects to store and manipulate rectangular areas. A Rect can be created from a combination of left, top, width, and height values. Rects can also be created from python objects that are already a Rect or have an attribute named “rect”.
"In place" means the object self.
While rect.move_ip
changes the pygame.Rect
object itself,
rect.move
does not change the object, but it returns a new object with the same size and "moved" position.
Note, the return value of rect.move_ip
is None
, but the return value of rect.move
is a new pygame.Rect
object.
rect.move_ip(x, y)
does the same as rect = rect.move(x, y)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With