0

I want to do stuff in my scene when it is transitioned to. Is there anything in cocos2d similar to viewDidLoad that is called when I switch to a scene or layer? Thanks

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142

1 Answers1

3

Yes, in the scene subclass implementation add:

-(void) onEnter
{
    [super onEnter];

    // your code here
}

-(void) onEnterTransitionDidFinish
{
    [super onEnterTransitionDidFinish];

    // your code here
}

The first runs immediately after the scene was presented, and if the scene is presented with a transition, the latter will run after the transition completed.

Note that calling the super implementation is mandatory. Otherwise you may lose input/update or other functionality.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217