Kivy淡入动画 [英] Kivy Fade-In Animation

查看:179
本文介绍了Kivy淡入动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在奇异果形的画布矩形背景上获得淡入/淡出动画?我通过使用Clock.schedule_interval()函数进行了尝试.但是在并发性和数据引发方面出现了一些问题.

Is there a way to get a fade-in/-out animation on a canvas rectangle background in kivy? I tried it by using the Clock.schedule_interval() function. But several problems occured concerning concurrency and data raise.

我的尝试之一如下:

 def calendarClicked(self, *args):
    self.alpha = 1.0
    self.alphaDelta = 0.01

    self.root.canvas.add(Color(1,0,0,self.alpha))
    self.root.canvas.add(Rectangle(size=self.root.size))

    def fadeIn(self, dt):

        self.alpha -= self.alphaDelta
        self.root.canvas.add(Color(1,0,0,self.alpha))
        self.root.canvas.add(Rectangle(size=self.root.size))

        return self.alpha >= 0.5

    Clock.schedule_interval(partial(fadeIn, self), 0.1)   

另一个想法是使用kivy.animation.但是我找不到一种方法来编辑颜色,而不是对象/窗口小部件的位置.

Another idea was to use the kivy.animation. But I coudn't find a way to edit the color instead of the position of an object/widget.

提前谢谢!

推荐答案

您可以在画布上使用Animation指令,就像使用小部件一样.问题在于您根本没有修改画布指令,只是不断添加越来越多的画布指令.您只需添加一次指令,然后通过Animation更新值.

You can use an Animation on canvas instructions just like you would a widget. The problem is that you're not modifying the canvas instructions at all, you just keep adding more and more canvas instructions. You need to add the instructions one time only, then update the values via Animation.

def calendarClicked(self, *args):
    if not hasattr(self, 'color'):
        with self.root.canvas:
            self.color = Color(1, 0, 0, 0)
            self.rect = Rectangle(size=self.root.size)

    self.color.a = 0
    anim = Animation(a=1.0)
    anim.start(self.color)

这篇关于Kivy淡入动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆