pyglet.input.Joystick and cocos events

62 views
Skip to first unread message

alex23

unread,
Aug 17, 2012, 3:06:14 AM8/17/12
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.

claudio canepa

unread,
Aug 17, 2012, 12:39:14 PM8/17/12
to cocos-...@googlegroups.com
Theres a bug in pyglet where the display is not updated, see

Add 
      self.schedule(lambda x: 0)

as last line in JoystickTest.__init__


alex23

unread,
Aug 17, 2012, 6:32:24 PM8/17/12
to cocos2d discuss
On Aug 18, 2:39 am, claudio canepa <ccanep...@gmail.com> wrote:
> Theres a bug in pyglet where the display is not updated

Ah, thank you. My fault for assuming it lay on the cocos/pyglet
border.

> Add
>       self.schedule(lambda x: 0)
>
> as last line in JoystickTest.__init__

I ended up chancing into this but wasn't sure if it would interfere
with cocos' event loop or anything else.

Cheers for your help.
Reply all
Reply to author
Forward
0 new messages