1

SneakyInput Joystick libを Cocos2d-x に移植する途中で、基本的にこの作業を完了することができましたが、奇妙な CCAssert エラーが発生することがあります。

CCNode::void CCSprite::addChild(CCNode *pChild, int zOrder, int tag)
{
 // ...
 CCAssert( pChildSprite, "CCSprite only supports CCSprites as children when using CCSpriteBatchNode"); // SIGABRT here
 // ...
}

私の側では、CCNode の「addChild」メソッドの呼び出しがここで行われています。

void SneakyButtonSkinnedBase::setButton(SneakyButton *pButton)
{
 if (button) {
    if (button->getParent()) {
        button->getParent()->removeChild(button, true); 
    }
    button->release();
 }

 pButton->retain();
 button = pButton;

 if (pButton) {
     this->addChild(button, 4); /* !!! crash here !!! */
     if (defaultSprite) {
         button->setRadius(defaultSprite->boundingBox().size.width/2);
     }
 }

/* Original iOS code */     

//    if(button){
//      if(button.parent)
//          [button.parent removeChild:button cleanup:YES];
//      [button release];
//  }
//  button = [aButton retain];
//  if(aButton){
//      [self addChild:button z:4];
//      if(defaultSprite)
//          [button setRadius:defaultSprite.contentSize.width/2];
//  }
}

何が起こっているのかまったくわかりません。自分のプロジェクト (およびライブラリにも) に BatchNode クラスへの参照がありません。さらに、エラーがランダムに表示されます (10 回の試行で 7 ~ 8 回)。私は疑問に思っています - それはフレームワークの隠されたロジックですか?いくつかの同様のスプライトをレイヤー (4 つのナビゲーション ボタン) に追加しようとすると、何らかの変換が実行されますか? この場合、cocos2-d でエラーなく動作するのはなぜですか?

4

0 に答える 0