Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在场景转换到时在我的场景中做一些事情。cocos2d 中是否有任何类似于 viewDidLoad 的东西,当我切换到场景或图层时会调用它?谢谢
是的,在场景子类实现中添加:
-(void) onEnter { [super onEnter]; // your code here } -(void) onEnterTransitionDidFinish { [super onEnterTransitionDidFinish]; // your code here }
第一个在场景呈现后立即运行,如果场景呈现有过渡,后者将在过渡完成后运行。
请注意,调用超级实现是强制性的。否则您可能会丢失输入/更新或其他功能。