在 pygame 中将表面传输到屏幕的正确顺序是什么?
我正在创建一个简单的 mp3 播放器,我的第一个任务是创建一个用户可以按下的简单按钮。我创建了一个名为 Button 的类,它处理此行为并检测用户是否单击了它,然后更改颜色。我现在尝试设置按钮显示的默认文本和按下按钮时将显示的另一个字符串(pres_string)。
唯一的问题是我的背景表面似乎位于错误的位置,并且正在覆盖我所做的任何更改。
这是我的代码:
正如你所看到的,我已经注释掉了这些行我在主函数中使用基本变量进行了描述和尝试,只是为了测试出了什么问题。
感谢您的任何帮助。
(随意更改问题的标题,我不确定什么最准确地描述了我的问题)
I am creating a simple mp3 player and my first task was to create a simple button that a user could press. I created a class called Button which handled this behavior and detects if a user has clicked it and then changes color. I am now trying to have a default text that the button displays and another string (pres_string) which will be displayed if the button is being pressed.
The only problem is my background surface seems to be in the wrong place and is drawing over any changes I have made.
Here is my code:
As you can see I've commented out the lines I described and tried it with basic variables in the main function just to test what was going wrong.
Thanks for any help.
(Feel free to change the title of the question, I wasn't sure what most accuratelydescribed my problem)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每个循环提示清除表面
:对于颜色,您可以使用诸如
red
之类的人类名称来调用 pygame.Color() (gray20
和gray80
有一个很好的对比,用于背景和文本)您的按钮,伪代码。修复:将颜色移动为实例成员。
对于
testClick
使用Rect.collidepoint
http://www.pygame.org/docs/ref/rect.html#Rect.collidepointClear the surface every loop
tip: For colors, you can call pygame.Color() with human-names like
red
(gray20
andgray80
have a nice contrast, to use for bg and text. )Your button, psuedocode. Fix: moved color as an instance member.
For
testClick
useRect.collidepoint
http://www.pygame.org/docs/ref/rect.html#Rect.collidepoint基于 2D 位图的计算机图形就像绘图或绘画 - 您将新墨水放在已有的内容之上。所以你每次画的第一件事一定是你的背景。
2D bitmap-based computer graphics are like drawing or painting - you put the new ink on top of whatever was there already. So your background must be the first thing you draw each time.