2013年6月19日水曜日

【cocos2d-x】アプリがバックグラウンドから復帰した時にSceneのメソッドを呼ぶ。

アプリがバックグラウンドから復帰した時などに現在のシーンにアクセスする方法です。 時間をとって画面を変化させたいときなどに使えます。
viewDidAppearとかviewWillAppearみたいなのが無さそうなので。(あったら教えて下さい)
HelloWorldSceneのhogeメソッドを読んでいます。

AppDelegate.cpp
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->startAnimation();
    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
    SimpleAudioEngine::sharedEngine()->resumeAllEffects();

     // getRunningSceneでCCSceneをとってその上のレイヤーにアクセスする。
    CCLayer *sceneLayer = (CCLayer*)CCDirector::sharedDirector()->getRunningScene()->getChildren()->lastObject();
    if (typeid(*sceneLayer) == typeid(HelloWorld)) {
        HelloWorld *helloWold = (HelloWorld*)sceneLayer;
        helloWold->hoge();
    }
} 
getRunningSceneでそのままアクセスできると思ってしばらくハマってました。
sceneメソッド見て納得。

0 件のコメント: