Pygame的消息多行?(Pygame's Message

系统教程 行业动态 更新时间:2024-06-14 16:57:18
Pygame的消息多行?(Pygame's Message-multiple lines?)

我正在使用pygame和livewires(虽然我不认为这部分是相关的)来创建游戏。 我已经让游戏正常运行了,但是我想在比赛开始之前做一些类似于标题画面的东西。 但是,当我尝试显示新行时,它无法识别。 这是我有的:

begin_message=games.Message(value=""" Destroy the Bricks!\n In this game, you control a paddle,\n controlled by your mouse,\n and attempt to destroy all the rows of bricks.\n Careful though, you only have 1 life.\n Don't mess up! The game will start in\n 5 seconds.""", size=30, x=games.screen.width/2, y=games.screen.height/2, lifetime=500, color=color.white, is_collideable=False) games.screen.add(begin_message)

消息显示在屏幕上,但换行没有发生,因此我只能阅读消息的第一部分。 有没有办法让这条消息真正出现,或者我可以不使用“消息”吗?

I am using pygame and livewires (though I don't think that part is relevant here) to create a game. I've got the game working, but I'm trying to make something akin to a title screen before the game starts. However, it doesn't recognize when I try to make a new line appear. Here is what I have:

begin_message=games.Message(value=""" Destroy the Bricks!\n In this game, you control a paddle,\n controlled by your mouse,\n and attempt to destroy all the rows of bricks.\n Careful though, you only have 1 life.\n Don't mess up! The game will start in\n 5 seconds.""", size=30, x=games.screen.width/2, y=games.screen.height/2, lifetime=500, color=color.white, is_collideable=False) games.screen.add(begin_message)

The message appears on the screen, but the newline doesn't happen, so I can only read the first part of the message. Is there a way to make this message actually appear, or can I not use the 'Message' for this?

最满意答案

livewires games.Message类不能这样做。

浏览games.Message的源代码表明它继承自games.Text,它有一个方法_create_surface()。 最后,这会调用pygame.font.Font.render()将文本绘制到曲面。 如果你看一下render()的文档 ,它就说明了

“文本只能是一行:不会呈现换行符。”

至于你如何做你想做的事情,我建议你制作几个Message对象,每行一个。 然后一个接一个地在屏幕上显示它们。

The livewires games.Message class cannot do this.

Going through the source code for games.Message shows that it inherits from games.Text, which has a method _create_surface(). Finally, this calls pygame.font.Font.render() to draw the text to a surface. If you look at the documentation for render(), it states

"The text can only be a single line: newline characters are not rendered."

As for how you'd do what you want, I'd suggest making several Message objects, one for each line. Then display them on the screen one after the other.

更多推荐

本文发布于:2023-04-12 20:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/fc5afd9bd860241b1830630b5978b8bc.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   Pygame   Message

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!