Android Kivi plyer and accelerometer

73 views
Skip to first unread message

laurent morel

unread,
Apr 25, 2017, 4:57:00 PM4/25/17
to Kivy users support
Hello ,

In inspiration of Pong Tutorial with Kivy , we are trying to move the ball with plyer accelerometer.

Here is the code but i have got some mistakes :

TypeError : 'kivy.properties.ReferenceListProperty' Object is not iterable

The code :

from kivy.app import App

from kivy.uix.widget import Widget

from kivy.properties import NumericProperty, ReferenceListProperty, ObjectProperty

from kivy.vector import Vector

from kivy.clock import Clock

from kivy.uix.floatlayout import FloatLayout

from kivy.uix.label import Label

from kivy.graphics import *

from plyer import accelerometer



class LabBall(Widget):

def __init__(self, **kwargs):

super(LabBall, self).__init__(**kwargs)

self.velocity_x = NumericProperty(0)

self.velocity_y = NumericProperty(0)

self.velocity = ReferenceListProperty(self.velocity_x, self.velocity_y)

self.acc_x = NumericProperty(0)

self.acc_y = NumericProperty(0)

val = accelerometer.acceleration[:3]

if val == (None, None, None):

self.acc_x=0

self.acc_y=0

else :

self.acc_x= accelerometer.acceleration[0]

self.acc_y= accelerometer.acceleration[1]

self.acc =ReferenceListProperty(self.acc_x,self.acc_y)

def move(self):

self.velocity = Vector(self.acc)+Vector(self.velocity)


self.pos = Vector(*self.velocity) + self.pos


class LabGame(Widget):


ball = ObjectProperty(None)



def __init__(self, **kwargs):

super(LabGame, self).__init__(**kwargs)

self.murs_verts = [[[0, 0], [0, self.height]], [[self.width, 0], [self.width, self.height]]]

self.murs_horiz = [[[0, 0], [self.width, 0]], [[0, self.height], [self.width, self.height]]]


def serve_ball(self, vel=(0,0)):

self.ball.center = self.center

self.ball.velocity = vel


def update(self, dt,**kwargs):

super(LabGame, self).__init__(**kwargs)

self.ball.move()




class LabApp(App):


def build(self):

game = LabGame()

game.serve_ball()

Clock.schedule_interval(game.update, 1.0 / 60.0)

return game



if __name__ == '__main__':


LabApp().run()



If i chage the line : self.velocity = Vector(self.acc)+Vector(self.velocity) to self.velocity = Vector(*self.acc)+Vector(*self.velocity)

I have the message : Type Object argument after * must be a sequence, not kivy.properties.ReferenceListPropertiy



Sombody please can help us


Thanks a lot


Fari Tigar

unread,
Apr 26, 2017, 3:25:21 AM4/26/17
to Kivy users support
Out of curiosity: how do you test the accelerometer on a Linux / Windows desktop?

laurent morel

unread,
Apr 26, 2017, 4:31:17 AM4/26/17
to kivy-...@googlegroups.com
I can t unfortunatly. I have toi transfert un thé Android sévices each Timmermans i want tout test
😫😓😒

--
You received this message because you are subscribed to a topic in the Google Groups "Kivy users support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/kivy-users/SKgru9RjVYk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to kivy-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

SUSMIT

unread,
Apr 26, 2017, 11:06:08 AM4/26/17
to kivy-...@googlegroups.com
Hi
The following link will aid you link
Second accelerometer is not implemented for windows and on linux it will most probably give you "Could not enable accelerometer!" exception. 

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+unsubscribe@googlegroups.com.

laurent morel

unread,
Apr 26, 2017, 11:41:45 AM4/26/17
to kivy-...@googlegroups.com
I already Saw this link ans it works on my Android. 
I run my script on Android with kivylauncher. I have errors on my kivy. Log

Thanks for tout help

Reply all
Reply to author
Forward
0 new messages