something similar to viewDidLoad in Cocos2d

361 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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.