import pygame, sys
from pygame.locals import *
WINDOW_WIDTH = 500
WINDOW_HEIGHT = 500
pygame.init()
DISPLAYSURF = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
def display_text_animation(string):
text = ''
for i in range(len(string)):
DISPLAYSURF.fill(WHITE)
text += string[i]
text_surface = font.render(text, True, BLACK)
text_rect = text_surface.get_rect()
text_rect.center = (WINDOW_WIDTH/2, WINDOW_HEIGHT/2)
DISPLAYSURF.blit(text_surface, text_rect)
pygame.display.update()
pygame.time.wait(100)
def main():
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
display_text_animation('Hello World!')
main()
Run Code Online (Sandbox Code Playgroud)
注意:我以前没有使用过 pygame,所以这可能不起作用。
| 归档时间: |
|
| 查看次数: |
5351 次 |
| 最近记录: |