[英]How can I insert a console in to a pyGame Window?
I'm making a text adventure, and I want to have pyGame animations and illustrations and a HUD! 我正在进行文字冒险,我希望有pyGame动画,插图和HUD!
How can I insert this console? 我该如何插入此控制台?
Thanks! 谢谢!
I'm pretty sure that's impossible. 我很确定这是不可能的。 If you want a console within a Pygame screen then you'll have to write your own, or find one written by someone else (eg http://pygame.org/project-pygame-console-287-.html ) 如果你想在Pygame屏幕中使用控制台,那么你必须自己编写,或者找到其他人编写的控制台(例如http://pygame.org/project-pygame-console-287-.html )
For your game, you can use subsurface , for the different screen 'sections'. 对于您的游戏,您可以使用地下 ,用于不同的屏幕“部分”。
Using python 3x will have issues with multiple libraries, that are not precompiled for you. 使用python 3x会出现多个库的问题,这些库不是为您预编译的。 If you can, it will simplify things to Use 2.7 or 2.6. 如果可以,它将简化使用2.7或2.6的内容。 (There is a python2.7 binary, but not on the front page) (有一个python2.7二进制文件,但不在首页)
A console isn't too hard. 控制台不是太难。 You need to break down the components, deciding what you need. 您需要分解组件,决定您需要什么。 Start with a miniproject, implementing features one at a time. 从一个小型项目开始,一次实现一个功能。
dict()
of strings, for commands, with values of function names. 字符串的dict()
,用于命令,具有函数名称的值。 commands = { "n" : move_north, "s" : move_south, "fps" : toggle_fps, "help" : print_help } commands = {“n”:move_north,“s”:move_south,“fps”:toggle_fps,“help”:print_help}
On enter, call the dict's value, if key exists: 在输入时,如果密钥存在,则调用dict的值:
if cmd in commands:
commands[cmd]()
# same as commands["n"]()
You could even have the console's print_help() use the function docstrings. 你甚至可以让控制台的print_help()使用docstrings函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.