Hello again!

Reading one of the demos for reference, I've created a layer that
enables pyglet events.

However, the game quits when I press the ESCAPE key, even though I
don't handle that.

It looks like it is handled by director.

I tried to get around this with a simple test example, show below.
(Sorry, I don't know how to format it to make it show up as "code".)

import sys
import os

import cocos
from cocos.director import director
from cocos.layer import Layer
from cocos.scene import Scene

import pyglet
from pyglet.window import key



class TestLayer(cocos.layer.Layer):
    is_event_handler = True     #: enable pyglet's events

    def __init__(self):
        super(TestLayer,self).__init__()
        self.keys_pressed = set()

    def draw( self ):
        super(TestLayer,self).draw()

    def on_key_press (self, akey, modifiers):
        self.keys_pressed.add (akey)

#here is where i might handle the keys myself, including ESCAPE to
bring up the main menu


    def on_key_release (self, akey, modifiers):
        self.keys_pressed.remove (akey)

if __name__ == "__main__":
    director.init(resizable=False, width=1024, height=768)
    test_layer = TestLayer()
    main_scene = Scene (test_layer)
    director.window.pop_handlers()
    director.run (main_scene)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cocos-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to