|
47 | 47 | top, left, bottom, right
|
48 | 48 | topleft, bottomleft, topright, bottomright
|
49 | 49 | midtop, midleft, midbottom, midright
|
50 |
| - center, relcenter, centerx, centery |
51 |
| - size, width, height |
| 50 | + center, centerx, centery |
| 51 | + size, width, height, relcenter |
52 | 52 | w,h
|
53 | 53 |
|
54 | 54 | All of these attributes can be assigned to:
|
|
58 | 58 | rect1.right = 10
|
59 | 59 | rect2.center = (20,30)
|
60 | 60 |
|
61 |
| - Assigning to size, width or height changes the dimensions of the rectangle; |
| 61 | + Assigning to size, width, height, or relcenter changes the dimensions of the rectangle; |
62 | 62 | all other assignments move the rectangle without resizing it. Notice that
|
63 | 63 | some attributes are integers and others are pairs of integers.
|
64 | 64 |
|
|
94 | 94 | overridden if any extra attributes need to be copied.
|
95 | 95 |
|
96 | 96 | .. versionadded:: 2.5.6
|
97 |
| - ``relcenter`` added to Rect / FRect. This will return you a ``Point`` of |
98 |
| - the center relative to the topleft of the Rect. Setting a ``Point`` to it will |
99 |
| - modify the size of the rect to 2 times the ``Point`` used. Below you can find a |
100 |
| - code example of how it should work : |
| 97 | + ``relcenter`` added to Rect / FRect. This will return a tuple containing half |
| 98 | + the Rect's size; the center relative to the topleft of the Rect. |
| 99 | + Setting it to a ``Point`` will modify the size of the rect to 2 times |
| 100 | + the ``Point`` given. Below you can find a code example of how it should work: |
101 | 101 |
|
102 | 102 | .. code-block:: python
|
103 | 103 |
|
104 |
| - > my_rect = pygame.Rect(0, 0, 2, 2) |
105 |
| - > my_rect.relcenter |
106 |
| - > (1, 1) |
107 |
| - > my_rect.relcenter = (128, 128) |
108 |
| - > my_rect.relcenter, my_rect.size |
109 |
| - > ((128, 128), (256, 256)) |
| 104 | + >>> my_rect = pygame.Rect(0, 0, 2, 2) |
| 105 | + >>> my_rect.relcenter |
| 106 | + (1, 1) |
| 107 | + >>> my_rect.relcenter = (128, 128) |
| 108 | + >>> my_rect.size |
| 109 | + (256, 256) |
110 | 110 |
|
111 |
| - Beware of non integer relative centers ! Using a Rect instead of FRect will round down |
112 |
| - the values of the returned ``Point``. |
| 111 | + Beware of non-integer relative centers! For Rects (but not FRects), ``relcenter`` |
| 112 | + will truncate the numbers in the returned tuple. |
113 | 113 |
|
114 | 114 |
|
115 | 115 | .. method:: copy
|
|
0 commit comments