Table Of Contents
Kinetic effect¶
New in version 1.7.0.
The KineticEffect is the base class that is used to compute the
velocity out of a movement. When the movement is finished, the effect will
compute the position of the movement according to the velocity, and reduce the
velocity with a friction. The movement stop until the velocity is 0.
Conceptually, the usage could be:
>>> effect = KineticEffect()
>>> effect.start(10)
>>> effect.update(15)
>>> effect.update(30)
>>> effect.stop(48)
Over the time, you will start a movement of a value, update it, and stop the
movement. At this time, you’ll get the movement value into
KineticEffect.value. On the example i’ve typed manually, the computed
velocity will be:
>>> effect.velocity
3.1619100231163046
After multiple clock interaction, the velocity will decrease according to
KineticEffect.friction. The computed value will be stored in
KineticEffect.value. The output of this value could be:
46.30038145219605
54.58302451968686
61.9229016256196
# ...
- class kivy.effects.kinetic.KineticEffect(**kwargs)¶
Bases:
kivy.event.EventDispatcherKinetic effect class. See module documentation for more information.
- cancel()¶
Cancel a movement. This can be used in case
stop()cannot be called. It will resetis_manualto False, and compute the movement if the velocity is > 0.
- halt()¶
Stop the movement immediately without momentum. This method immediately stops any ongoing kinetic scrolling effect by: - Cancelling any scheduled velocity updates to prevent further movement - Setting is_manual to False to indicate no manual interaction is in progress
Unlike the stop() method which calculates final velocity for momentum scrolling, this method provides instant cessation of movement without any residual animation.
This is useful when you need to programmatically stop scrolling in response to user actions or when the scroll position needs to be fixed immediately. The halt() method is called by ScrollView.scroll_to to stop scrolling animation prior to moving to the target widget.
- start(val, t=None)¶
Start the movement.
- Parameters:
- val: float or int
Value of the movement
- t: float, defaults to None
Time when the movement happen. If no time is set, it will use time.time()
- update_velocity(dt)¶
(internal) Update the velocity according to the frametime and friction.