Pygame Define Different Position Order Make The Different Result
Solution 1:
self.setting.screen_rect.center
is the center of the large screen. But the text is not blit
onto the screen, it is blit on the small text_surface
.
self.text_surface.blit(self.text,self.text_rect)
The size of text_surface
is (400, 100), but the center of self.text_rect
is (600, 400).
If you do
self.text_surface_rect.center = self.setting.screen_rect.center [...] self.text_rect.center = self.text_surface_rect.center
then self.text_surface_rect
has a location which is far out of the bounds of self.text_surface
. The center of the screen (self.setting.screen_rect.center
) is (600, 400). But the size of text_surface is (400, 100).
+--------------+
| text_surface |
+--------------+
size: (400, 100)
+----------+
| text_rect| center: (600, 400)
+----------+
Note text_surface_rect
is (400, 350, 400, 100)
, but text_surface
is a Surface object and has no location it has just a size of (400, 100). You can think about it as a rectangle (0, 0, 400, 100).
The text is blit
on text_surface
not on text_surface_rect
.
You have to compute the location relative to self.button_surface_rect
, rather than self.setting.screen
:
self.text_surface_rect.center = (self.setting.screen_rect.centerx - self.button_surface_rect.x,
self.setting.screen_rect.centery - self.button_surface_rect.y)
Post a Comment for "Pygame Define Different Position Order Make The Different Result"