我如何在pygame中实现滚动文本?由于Text类是从Sprite派生的,我以为我能够以通常的方式将它包装成Sprite对象。相反,它只是从屏幕的左边缘消失,永远不会返回(我不能让它从每一侧反弹)。
我的目标是加强我在一些教育材料中所涵盖的内容。但是,滚动文本并不是其中之一(虽然看起来很酷)。
谢谢,
戴夫
代码(特定区块正在评论'在屏幕底部添加滚动文字'):
# Simon Says
# Displays sequences of sounds and/or colors which the user must repeat
from livewires import games, color
import random
# initialise screen
games.init(screen_width = 640, screen_height = 480, fps = 50)
class Game(object):
"""A sequence repeat game"""
def __init__(self):
"""Initialize Game object"""
# create key
self.menu_title = games.Text(value = "Key",
size = 25,
color = color.red,
top = 5,
left = games.screen.width - 100,
is_collideable = False)
self.menu_choice0 = games.Text(value = "0 - Quit",
size = 20,
color = color.red,
top = self.menu_title.bottom + 5,
left = games.screen.width - 120,
is_collideable = False)
self.menu_choice1 = games.Text(value = "1 - Yellow",
size = 20,
color = color.red,
top = self.menu_choice0.bottom + 5,
left = games.screen.width - 120,
is_collideable = False)
self.menu_choice2 = games.Text(value = "2 -Thrust sound",
size = 20,
color = color.red,
top = self.menu_choice1.bottom + 5,
left = games.screen.width - 120,
is_collideable = False)
games.screen.add(self.menu_title)
games.screen.add(self.menu_choice0)
games.screen.add(self.menu_choice1)
games.screen.add(self.menu_choice2)
# add scrolling text at bottom of screen
self.instructions = games.Text(value = "Repeat the sequence by entering the "
"corresponding number.",
size = 20,
color = color.green,
x = games.screen.width/2,
bottom = games.screen.height - 2,
dx = - 0.75)
games.screen.add(self.instructions)
# wrap
if self.instructions.left < 0:
self.instructions.left = games.screen.width
def play(self):
"""Play game"""
# load and set background
black_background = games.load_image("blackbackground.jpg", transparent = False)
games.screen.background = black_background
games.screen.mainloop()
def main():
sequence = Game()
sequence.play()
main()
答案 0 :(得分:1)
在livewires
中,我没有看到任何可以处理这一切的内容。您可以将livewires.Object
与一些自定义代码一起使用。像livewires.game.Text
那样构建你的表面然后移动它。或者甚至使它可以勾选并跟踪应该显示的文本部分以及blit
该部分到对象表面。