Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between rect.move() and rect.move_ip in pygame

Tags:

python

pygame

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?

like image 238
Jdeep Avatar asked May 03 '20 17:05

Jdeep


People also ask

What does Move_ip do in Pygame?

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.

How do you move a rect object in Pygame?

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.

What does rect () do?

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.

What does rect do in Pygame?

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”.


Video Answer


1 Answers

"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)

like image 73
Rabbid76 Avatar answered Oct 19 '22 23:10

Rabbid76