Los métodos de entrada en Kivy

Agrawal malayo:

Yo estaba tratando de conseguir el movimiento continuo contacto en Kivy para mover un rectángulo para el que escribí un código

from kivy.app import App
from kivy.uix.button import Label
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
from kivy.core.window import Window

class Game(Widget):
    def __init__(self,**kwargs):
        super().__init__(**kwargs)
        with self.canvas:
            Color=(0,1,0,1)
            self.player=Rectangle(pos=(50,0),size=(20,50))



#touch and motion of our player
    def on_motion(self,etype,motionevent,**kwargs):
        print('hello')
        touch_condition=False
        x_touch=motionevent.spos[0]
        xa=self.player.pos[0]
        ya=self.player.pos[1]
        if etype=='begin' or etype=='update':
            touch_condition=True
        if etype=='end':
            touch_condition=False


        if touch_condition and x_touch>0.5:
            xa+=10
        if touch_condition and x_touch<0.5:
            xa-=10      

        self.player.pos=(xa,ya)

    Window.bind(on_motion=on_motion)



class Try(App):
    def build(self):
        return Game()

if __name__=="__main__":
    Try().run()

Al hacer clic con el ratón como una entrada a su dando un error

Archivo "kiv.py", línea 21, en on_motion xa = self.player.pos [0] AttributeError: objeto 'WindowSDL' no tiene atributo 'jugador'

He leído toda la documentación en los insumos y Kivy Window.bindpero sigo siendo incapaz de entender cómo resolverlo.

inclemencias:

Su estructura de clases está en mal estado, que está vinculante on_motiona nivel de clase. Me sorprende que este es el error que se obtiene, pero que se ve como el problema.

Añadir Window.bind(on_motion=self.on_motion)en el __init__de su juego widget de lugar.

Supongo que te gusta

Origin http://10.200.1.11:23101/article/api/json?id=406062&siteId=1
Recomendado
Clasificación