Text issues on pygame
Im making a Pong game that displays the player and enemy score based on
the screen width. Both scores should keep a 20 pixels distance from the
middle of the screen and everything was working just fine but i've ran in
to some problems:
First, i've made the game in a way that the player can be in both sides,
left or right. When the scores are initialized, some attributes are passed
to a Text class (like top or centerx) and these attributes will define
where it should be placed. I tried to do it like:
self.player_score = Text(self.player.score, 32, WHITE,
top = 10, right = SCREEN_WIDTH/2 - 20)
self.enemy_score = Text(self.player.score, 32, WHITE,
top = 10, left = SCREEN_WIDTH/2 + 20)
but since the player and sides can change thats not a good solution.
Second, I want the text to always be at the same distance from the center
of the screen, but when the score grows to two or more digits the text
occupies more space. For the right side its not a problem, but for the
left side the text keeps getting closer and closer to the middle of the
screen. Here's the set_value method from my Text class:
def set_value(self, new_value):
if new_value != self._value:
self._value = new_value
self.image = self._create_surface()
self.rect = self.image.get_rect(top = self.rect.top,
bottom = self.rect.bottom,
left = self.rect.left,
right = self.rect.right,
centerx = self.rect.centerx,
centery = self.rect.centery)
How can I solve these problems?
No comments:
Post a Comment