开发者

Pygame's Message-multiple lines?

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
 开发者_StackOverflow社区                                   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?


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.


There are several text rendering projects for pygame, on the site. Some are python modules ( that you can include the file locally, without installing. )

A more advanced one is Glyph.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜