1) Don't use globals. This should technically work, but it's bad practice and in this case there's no downside to simply adding a variable to your class. NotNone has this very moment posted an example of how to do so with a kivy property, which adds some other behaviour you may find convenient later.
2) Your move function isn't compatible with an eventloop driven gui like kivy (or many other gui libraries). The problem is that the while
function is a blocking call - all of kivy's normal tasks can't be performed until the move
function terminates. Detecting and propagating touch is one of these things, so on_touch_up
will never be called, and the touched_down
variable will never become False.
You probably instead want to do something like:
from kivy.clock import Clock
def on_touch_down(self, touch):
Clock.schedule_interval(self.incremental_move, 0)
def on_touch_up(self, touch):
Clock.unschedule(self.incremental_move)
def incremental_move(self, dt):
# write code for movement in the time dt here
Using the clock like this inserts the movement into the normal kivy eventloop, so it's called every frame without blocking everything else.
It might also be more natural to have an update
function that is always scheduled (and does other things too), and use a self.touched_down
attribute as above to optionally perform movement during that function.