Nattōsai Mitō
Nattōsai Mitō

Reputation: 918

Why touches sometimes look like already moved or already ended on_touch_down

MotionEvent has time_start, time_update and time_end attributes. I thought they can be used to know if a touch has already ended or not, but it looks like not. Here is the code that can confirm that.

from kivy.app import runTouchApp
from kivy.lang import Builder

runTouchApp(Builder.load_string('''
Widget:
    on_touch_down:
        t = args[1]
        has_not_moved = t.time_start == t.time_update
        has_not_ended = t.time_end == -1
        print(t.uid, has_not_moved, has_not_ended)
'''))

When I mashed a mouse button, I expected the output to be like this:

# I expect there is no False

1 True True
2 True True
3 True True
.
.
15 True True

but the actual output was

1 True True
2 True True
3 True True
.
13 True False
.
15 False False
.
20 False True

Why sometimes False was printed? Is there a guaranteed way to know if a touch has already ended or not?

the source code of MotionEvent

environment

Upvotes: 0

Views: 50

Answers (1)

inclement
inclement

Reputation: 29488

I don't know exactly what's going on here because I didn't check the source, but maybe it's something like surprising behaviour happening if you manage to touch and release within the same frame.

Is there a guaranteed way to distinguish touches?

You get a different touch object for each touch, so they are automatically distinguished.

Upvotes: 1

Related Questions