alex23
unread,Aug 17, 2012, 3:06:14 AM8/17/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to cocos2d discuss
Hi everyone,
I'm currently trying to get the Joystick input devices for pyglet 1.2
to play nicely with cocos. I've naively tried the following:
from cocos.director import director
from cocos import scene
from cocos import layer
from cocos import text
from pyglet import input
class JoystickTest(layer.Layer):
is_event_handler = True
def __init__(self):
super( JoystickTest, self ).__init__()
self.display = text.Label(
'--',
font_name='Times New Roman',
font_size=32,
anchor_x='center', anchor_y='center',
position = (320, 240),
)
self.add( self.display )
def on_enter(self):
super(JoystickTest, self).on_enter()
self.joy = input.get_joysticks()[0]
self.joy.on_joyaxis_motion = self.on_joyaxis_motion
self.joy.open()
def on_joyaxis_motion(self, joystick, axis, value):
self.update_text(axis)
def update_text(self, text):
print text
self.display.element.text = text
director.init()
director.run( scene.Scene( JoystickTest() ) )
The update_text call is printing to the console but the Label itself
isn't updating. I _thought_ using joystick.open() would be enough to
register it to the same event loop as cocos but I'm not entirely sure
if it is.
Any help would be greatly appreciated, thanks.