On Tue, Sep 17, 2013 at 4:22 AM, Paul Pittlerson <[email protected]>wrote:

> That's very informative and helpful, but it's a lot of info to take into
> consideration, especially for a novice like me. I will surely have more
> questions on the subject in the future.
>
> Here is one question regarding event handling within cocos.
>
> This is what I did in the EventDispatcher subclass for now (it's a map
> editor):
>
> types = [
>>             'show_menu',
>>             'hide_menu',
>>             'create_label',
>>             'clear_labels',
>>             'create_tiles',
>>             'place_tile',
>>             'remove_tile',
>>         ]
>>
>>         for event in types:
>>             self.register_event_type(event)
>>
>
>
This looks correct, assuming the self there is subclass of
pyglet.event.EventDispatcher



> The documentation says to do this as Emitter.register_event_type('...')
> rather than self, but in this case there will not be multiple emitters
> being created and removed so I think this is fine.
>

I don't understand. The code creates one emitter for each element in types,
so it create multiple emitters. It works because when python goes to
resolve self.register_event_type first it looks if any attribute
'register_event_type' in the instance, it found none so it tries to resolve
to a class method.



> Have I misunderstood the use of this? It seems to be the same sort of
> thing as is happening in the Tetrico example.
>
> I guess what I'm confused about is the semantics of this, because
> 'register event type' sounds like what the listener would do, rather then
> the emitter.
>

Sometimes the names seem weird at first, but it has sense.
Think about the question 'which events this EventDispatcher can be
subscribed ?'
Well, is the set of all names registered with register_event_type

In particular, when later you try to register a listener for event 'zzz'
with this event dispatcher, the dispatcher will verify that 'zzz' is a
registered event.


> Is it possible to implement this without predefining all the event types,
> and registering them in this manner? Any instructions are appreciated.
>

 You can add event types at any time, but, as you can't register to listen
to an unregistered event type, is probably not advisable. Meaning, now you
will have to be very careful about when you can register a listener.

-- 
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to