フレームワークの話になりますが、開発を開始する時期が少し早かったために、Nana Live+には最新のcocos2d-xのバージョンを使えていません。別のアプリには、cocos2d-x3.0台を利用しているのですが、バージョン2台から変更されているわかりにくい部分があったので紹介します。(Webで調べても出ないので、当たり前に知られている方法があるのかもしれないのですが。)


つまずいたのが「Component」を使う時です。
以前では、何か処理をさせたいNodeに対してComponentをくわせることで、そのNodeを貼り付けると同時にComponentのUpdate処理が動作していました。ところが、バージョン3.0ではNodeを貼り付けてもComponentのUpdate処理が自動的に動作しません。

ComponentContainer.cppの中身を見ると違いがありました。

bool ComponentContainer::add(Component *com)
{
    bool ret = false;
    CCASSERT(com != nullptr, "Argument must be non-nil");
    CCASSERT(com->getOwner() == nullptr, "Component already added...");
    do
    {
        if (_components == nullptr)
        {
            _components = new Map<std::string, component*="">();
        }
        Component *component = _components->at(com->getName());
        
        CCASSERT(component == nullptr, "Component already added...");
        CC_BREAK_IF(component);
        com->setOwner(_owner);
        _components->insert(com->getName(), com);
        com->onEnter();
        ret = true;
    } while(0);
    return ret;
}


bool CCComponentContainer::add(CCComponent *pCom)
{
    bool bRet = false;
    CCAssert(pCom != NULL, "Argument must be non-nil");
    CCAssert(pCom->getOwner() == NULL, "Component already added...");
    do
    {
        if (m_pComponents == NULL)
        {
            m_pComponents = CCDictionary::create();
            m_pComponents->retain();
            m_pOwner->scheduleUpdate();
        }
        CCComponent *pComponent = dynamic_cast<cccomponent*>(m_pComponents->objectForKey...
        
        CCAssert(pComponent == NULL, "Component already added...");
        CC_BREAK_IF(pComponent);
        pCom->setOwner(m_pOwner);
        m_pComponents->setObject(pCom, pCom->getName());
        pCom->onEnter();
        bRet = true;
    } while(0);
    return bRet;
}





「m_pOwner->scheduleUpdate();」がバージョン3.0にはありませんでした。
ですので、試しにスケジュールを追加してみるとバージョン2と同じような動作ができるようになりました。

bool ComponentContainer::add(Component *com)
{
    bool ret = false;
    CCASSERT(com != nullptr, "Argument must be non-nil");
    CCASSERT(com->getOwner() == nullptr, "Component already added...");
    do
    {
        if (_components == nullptr)
        {
            _components = new Map<std::string, component*="">();
            _owner->scheduleUpdate(); // 追加
        }
        Component *component = _components->at(com->getName());
        
        CCASSERT(component == nullptr, "Component already added...");
        CC_BREAK_IF(component);
        com->setOwner(_owner);
        _components->insert(com->getName(), com);
        com->onEnter();
        ret = true;
    } while(0);
    return ret;
}