On Mon, Nov 22, 2010 at 5:19 PM, Mike Wyatt <[email protected]> wrote:

> > > Fair warning - Redesign opportunity:
> > > Seems that the event propagation code was amidst a change for the
> > > 0.3.0 release, and then not ever completed.
> > > By example, Scenes and Layer supposedly inherits code from
> > > scene.EventHandlerMixin, but that code is never executed, and anyway
> > > in that code the line
> > >    scene = self.get(Scene)
> > > will traceback any time. ( probably wanted to be scene =
> > > self.get_ancestor(Scene) )
>
> I see.  Is properly implementing EventHandlerMixin as simple as fixing
> the above line and then calling EventHandlerMixin.add() and .remove()
> from the Scene, like this?
>
> +class Scene(cocosnode.CocosNode, EventHandlerMixin):
> +    def add(self, child, z=0, name=None ):
> +               super(Scene, self).add( child, z, name )
> +
> +    def remove(self, obj):
> +               super(Scene, self).remove( obj )
>
>
If we want to use mixin style, we begin by
    change the base classes order in Scene (that made the mixin's add
    be called, and the super in the mixin takes care to call CocosNode.add)

    replace
    scene = self.get(Scene)
with
    scene = self.get_ancestor(Scene)
    that eliminates a traceback, and looks as plausible (but needs to be
reexamined later to see what behavior will produce)

   To activate the mixin in Layer, we should similarly invert the base
classes
order, but here some other analysis and changes are needed:
  a) the mixin code duplicates code in Layer's on_enter on_exit, should we
     eliminate the later ?. probably yes
  b) how we handle a remove - add a layer to a running scene ? ( empty
     and reconstruct the stack probably)
  c) there is similar code in Layer and Scene (remove_all_handlers,
      push_all_handlers). Should we move some to the mixin ?

 By the way, reconstructing the stack in the add to respect front to back
can
be done calling remove_all_handler / push_all_handlers in the mixin, at the
scene level, (if the scene was running)

Will see to make a branch exploring this way.

But I can be better to use a component approach instead of a mixin one.
That way if a certain game don't fits well with the 'event propagation is
front to back'   it can make it own custom component and give it to the
scene and layer.
I will think about that.

--
claudio

-- 
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