def __init__(self, text, width=640, height=400, fps=30, textcolor=(0,0,255),
bgcolor=(255,255,255), font=('mono', 24, True), new_init=True, bg_filename=None):
"""Initialize pygame, window, background, font,...
default arguments
"""
#pygame.mixer.pre_init(44100, -16, 2, 2048)
if new_init:
pygame.init()
#jump = pygame.mixer.Sound(os.path.join('data','jump.wav')) #load sound
#self.sound1 = pygame.mixer.Sound(os.path.join('data','Pickup_Coin.wav'))
#self.sound2 = pygame.mixer.Sound(os.path.join('data','Jump.wav'))
#self.sound3 = pygame.mixer.Sound(os.path.join('data','mix.wav'))
pygame.display.set_caption("Press ESC to quit, curosr keys / PgUp, PgDown to scroll")
self.text = text
self.bgcolor = bgcolor
self.textcolor = textcolor
self.lines = text.split("\n")
self.width = width
self.height = height
self.screen = pygame.display.set_mode((self.width, self.height), pygame.DOUBLEBUF)
self.background = pygame.Surface(self.screen.get_size()).convert()
if bg_filename is None:
self.background.fill(self.bgcolor) # fill background white
else:
try:
print("i try to load:", bg_filename)
self.background = pygame.image.load(bg_filename)
self.background = pygame.transform.scale(self.background, (self.width, self.height))
except:
print("exception while processing:", bg_filename)
self.background.fill(self.bgcolor) # fill background white
self.clock = pygame.time.Clock()
self.fps = fps
self.playtime = 0.0
self.offset_y = self.height - 10
self.x = 100
self.dy = 50
self.text_height = len(self.lines) * self.dy
self.bold = font[2]
self.font = pygame.font.SysFont(font[0], font[1], self.bold)
textscroller_vertical.py 文件源码
python
阅读 27
收藏 0
点赞 0
评论 0
评论列表
文章目录