How to know when a layer becomes visible?

12 views
Skip to first unread message

Pascal LE MERRER

unread,
Apr 29, 2012, 4:57:00 PM4/29/12
to cocos-...@googlegroups.com
I would like to have a callback to be invoked when a layer becomes visible, and another one to be invoked when it become invisible.
I thought overriding the 'on_enter' and 'on_exit' methods would do the trick, but it appears they are invoked more than once :(
A solution for me could be to be notified of the end of the transition.

What is the best way to achieve this?

claudio canepa

unread,
Apr 29, 2012, 6:31:12 PM4/29/12
to cocos-...@googlegroups.com
To be notified at the end of transition you could do:

def get_transition_scene(fn_callback):
     def helper(self):
            super(TransitionSceneWhatever, self).on_exit()
            fn_callback()
 
     trans = TransitionSceneWhatever()
     trans.on_exit = helper
     return trans

This can be a bit before you really want to receive the call, so maybe this can work better

layer_to_notify = MyLayer()
layer_to_notify.after_transition = False

def get_transition_scene(layer_to_notify):
      def helper(self):
           super(TransitionSceneWhatever, self).on_exit()
           layer_to_notify.after_transition = True

      trans = TransitionSceneWhatever()
      trans.on_exit = helper
      return trans

Now in layer.on_enter you can check the flag to know if the transition ended.

claudio
Reply all
Reply to author
Forward
0 new messages