| 329 | |
| 330 | |
| 331 | class FadingText(object): |
| 332 | def __init__(self, font, dim, pos): |
| 333 | self.font = font |
| 334 | self.dim = dim |
| 335 | self.pos = pos |
| 336 | self.seconds_left = 0 |
| 337 | self.surface = pygame.Surface(self.dim) |
| 338 | |
| 339 | def set_text(self, text, color=(255, 255, 255), seconds=2.0): |
| 340 | text_texture = self.font.render(text, True, color) |
| 341 | self.surface = pygame.Surface(self.dim) |
| 342 | self.seconds_left = seconds |
| 343 | self.surface.fill((0, 0, 0, 0)) |
| 344 | self.surface.blit(text_texture, (10, 11)) |
| 345 | |
| 346 | def tick(self, _, clock): |
| 347 | delta_seconds = 1e-3 * clock.get_time() |
| 348 | self.seconds_left = max(0.0, self.seconds_left - delta_seconds) |
| 349 | self.surface.set_alpha(500.0 * self.seconds_left) |
| 350 | |
| 351 | def render(self, display): |
| 352 | display.blit(self.surface, self.pos) |
| 353 | |
| 354 | # ============================================================================== |
| 355 | # -- HelpText ------------------------------------------------------------------ |