Michal Lajčiak
Michal Lajčiak

Reputation: 11

Kivy animation - decreasing duration?

I have widget class in kivy, which I animate on screen. By the time I want to slowly decrease animation duration so widget will move faster. My code change the duration but it didn't affect on screen. Why?

my widget class:

class Obstacle3(Widget):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.animation = Animation(x =-self.width, duration=2)
        Clock.schedule_interval(self.faster, 2)
        self.anim = True
        self.animation.bind(on_complete=self.vanish)
        self.animation.start(self)
    def faster(self, *args):
        if self.animation._duration <= 0.4:
            self.animation._duration = self.animation._duration 
        else:
            self.animation._duration = self.animation._duration - 0.4

Upvotes: 1

Views: 297

Answers (1)

John Anderson
John Anderson

Reputation: 38857

Changing the duration after the animation has started will have no effect. But you can set the transition property of the Animation before you start it. To make the animation go faster later in the animation, try using in_circ, in_cubic, in_quart, in_quint, or in_expo.

Another approach is to call self.animation.stop(), then start another Animation when you want to increase the animation speed.

Upvotes: 1

Related Questions