KivyMD MDFlatButton 不可点击 & Kivy ScreenManager 不工作
KivyMD MDFlatButton not clickable & Kivy ScreenManager not working
所以我正在用 Kivy 制作这款游戏,这款游戏的开始屏幕有一个 MDToolbar
、一个 MDNavigationDrawer
、两个 Image
、三个 [=13] =]s 和一个 OneLineIconListItem
,上面写着 'Start Game',当你点击它时,游戏应该开始了。
游戏画面包含:
- 病毒
- 蒙面人
- 你用来杀病毒的肥皂
MDLabel
中的当前得分
- 返回开始屏幕的按钮
问题:
- 游戏的背景音乐在显示游戏画面之前开始播放(显示开始画面时)- ScreenManager 问题
- 当我单击按钮返回开始屏幕时,按钮未被单击 - MDFlatButton 问题
我在这款游戏中使用了 on_touch_down
、on_touch_move
和 on_touch_up
,我知道这就是导致 MDFlatButton
问题的原因。那么有谁知道我应该如何定义 on_touch_*
方法 AND 有可点击的按钮?
而且我也不知道如何解决 ScreenManager
问题。
我知道我没有在这里提供任何代码,但那是因为 post 变得太长了。我已经删除了 post,因为人们认为 post 太长,而且我提供的代码太多而细节太少。我不希望这种情况再次发生。如果有人需要查看我项目的代码,我会留下一个 Google Docs link 给它。
提前致谢!
我修复了我的应用程序。
以防万一有人有同样的问题,我会post在这里回答。
To get a clickable button, you have to create a new Screen
or Widget
and add the actual screen as a widget to the new class. Then, you can add buttons to the new class. This works because the button is on top of the actual screen. So when you click anywhere in the button's area, the button gets clicked and the on_touch_*
methods of the actual screen don't get called.
And to fix the ScreenManager
issue, you just have to expirement.
所以我正在用 Kivy 制作这款游戏,这款游戏的开始屏幕有一个 MDToolbar
、一个 MDNavigationDrawer
、两个 Image
、三个 [=13] =]s 和一个 OneLineIconListItem
,上面写着 'Start Game',当你点击它时,游戏应该开始了。
游戏画面包含:
- 病毒
- 蒙面人
- 你用来杀病毒的肥皂
MDLabel
中的当前得分
- 返回开始屏幕的按钮
问题:
- 游戏的背景音乐在显示游戏画面之前开始播放(显示开始画面时)- ScreenManager 问题
- 当我单击按钮返回开始屏幕时,按钮未被单击 - MDFlatButton 问题
我在这款游戏中使用了 on_touch_down
、on_touch_move
和 on_touch_up
,我知道这就是导致 MDFlatButton
问题的原因。那么有谁知道我应该如何定义 on_touch_*
方法 AND 有可点击的按钮?
而且我也不知道如何解决 ScreenManager
问题。
我知道我没有在这里提供任何代码,但那是因为 post 变得太长了。我已经删除了 post,因为人们认为 post 太长,而且我提供的代码太多而细节太少。我不希望这种情况再次发生。如果有人需要查看我项目的代码,我会留下一个 Google Docs link 给它。
提前致谢!
我修复了我的应用程序。
以防万一有人有同样的问题,我会post在这里回答。
To get a clickable button, you have to create a new
Screen
orWidget
and add the actual screen as a widget to the new class. Then, you can add buttons to the new class. This works because the button is on top of the actual screen. So when you click anywhere in the button's area, the button gets clicked and theon_touch_*
methods of the actual screen don't get called.
And to fix the
ScreenManager
issue, you just have to expirement.