Created
April 28, 2020 13:23
-
-
Save shorinji/23cafdb19c0e6bfa2ce9c7972591b3b2 to your computer and use it in GitHub Desktop.
Draws some text character by character with pygame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame | |
import sys | |
pygame.init() | |
screen = pygame.display.set_mode([800, 600]) | |
characters = list("Hello") | |
charsPrinted = 0 | |
delay = 1000 | |
fontSize = 16 | |
done = False | |
font = pygame.font.SysFont("georgiattf", fontSize) | |
print(font) | |
lastTime = pygame.time.get_ticks() | |
screen.fill(pygame.Color(100, 150, 200)) | |
while not done: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT or event.type == pygame.KEYDOWN: | |
sys.exit() | |
now = pygame.time.get_ticks() | |
if now - lastTime > delay: | |
lastTime = now | |
index = charsPrinted | |
textSurface = font.render(characters[index], True, pygame.Color(255, 255, 255)) | |
s = screen.blit(textSurface, [100 + (fontSize * index), 100]) | |
charsPrinted += 1 | |
if charsPrinted >= len(characters): | |
charsPrinted = 0 | |
pygame.display.flip() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment