-
Notifications
You must be signed in to change notification settings - Fork 0
/
text.py
32 lines (27 loc) · 919 Bytes
/
text.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pygame
class TextObject:
def __init__(self,
x,
y,
text_func):
self.pos = (x, y)
self.text_func = text_func
self.color = (0, 0, 0)
self.font = pygame.font.SysFont('Arial', 40)
self.bounds = self.get_surface(text_func())
def draw(self, surface, centralized=False):
text_surface, self.bounds = \
self.get_surface(self.text_func())
if centralized:
pos = (self.pos[0] - self.bounds.width // 2,
self.pos[1])
else:
pos = self.pos
surface.blit(text_surface, pos)
def get_surface(self, text):
text_surface = self.font.render(text,
False,
self.color)
return text_surface, text_surface.get_rect()
def update(self):
pass