【问题标题】:How do I know if Image is playing or has finished in Kivy?我如何知道 Image 在 Kivy 中是否正在播放或已结束?
【发布时间】:2020-07-26 20:34:23
【问题描述】:

我正在使用带有一堆 jpg 文件的 zip 文件来显示动画,因为加载 gif 文件太慢了。如果动画结束,我想更改当前屏幕。我如何知道 Image 是否仍在播放动画?有没有比根据动画的 fps 设置定时器更好的方法?

【问题讨论】:

    标签: python image animation kivy


    【解决方案1】:

    我不知道有什么方法可以捕获该信息。但这是一个丑陋的 hack。

    如果您将Imageanim_loop 设置为非零并添加loop_counton_texture 回调,如下所示:

    Image:
        loop_count: 0
        source: 'elephant.zip'
        anim_delay: 0.05
        anim_loop: 1
        on_texture: app.on_texture(self)
    

    然后App中的on_texture()方法可以判断动画是否完成:

    def on_texture(self, img):
        if img._coreimage.anim_index + 1 == len(img._coreimage.image.textures):
            # one animation loop complete
            img.loop_count += 1
            if img.loop_count == img.anim_loop:
                print('animation complete')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      • 2014-07-12
      • 1970-01-01
      • 2017-12-16
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      相关资源
      最近更新 更多