【问题标题】:Kivy Splash Screen image with fade in effect具有淡入效果的 Kivy 闪屏图像
【发布时间】:2016-09-07 01:09:19
【问题描述】:

我想知道如何使用 kivy 制作启动画面并在几秒钟内淡入显示图片。

我能做的最好的就是使用这段代码:

class MyApp(App):

    def __init__(self, **kwargs):
        super(MyApp, self).__init__(**kwargs)
        self.splash_screen_image = Image(source='images/pyrat_icon.png', size=(0, 0))
        Clock.schedule_once(self.start_anim, .01)

    def build(self):
        self.main_widget = MainWidget()
        return self.main_widget

    def start_anim(self, dt):
        self.splash_screen_image.pos = (self.main_widget.center_x, self.main_widget.center_y)
        self.main_widget.add_widget(self.splash_screen_image)
        animation = Animation(x=self.main_widget.center_x - 35, y=self.main_widget.center_y - 35, height=70, width=70, d=2,
                              t='in_quad')
        animation.start(self.splash_screen_image)
        Clock.schedule_once(self.end_anim, 3)

    def end_anim(self, dt):
        self.main_widget.remove_widget(self.splash_screen_image)

这会在屏幕上显示我的徽标,并在 3 秒后消失,但它会等待应用启动,因此当应用加载时只有一个黑色窗口。

【问题讨论】:

    标签: kivy splash-screen


    【解决方案1】:

    Android/iOS:

    在 python-for-android (presplash) 上默认使用 Splashscreen,在那里你可以设置你喜欢的任何图像。不知道它在ios上如何工作,但我认为也有启动画面。


    Windows/Linux/Mac/RPi:

    这些上不存在这样的东西。也许您可以在为操作系统打包时使用PyInstaller 设置一些东西,否则您需要自己制作。我可以推荐你使用ScreenManager 和它的Transitions 结合Clock 或者甚至Animation - 取决于你想要那个图像做什么。 Example

    要设置过渡外观的长度here,它应该可以在过渡中访问,例如FadeTransition(duration=1.5)

    【讨论】:

    • 好吧,我就是这么想的:/ 我已经添加了代码,可以缩放到我的徽标应用程序 3 秒然后消失。如果有一天 kivy 允许我们制作一个真正的启动画面,我会提出这个问题。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-10
    • 2016-01-30
    • 1970-01-01
    • 2012-12-21
    • 2023-03-31
    相关资源
    最近更新 更多