Cocos2d x CCSpriteBatchNode断言发生在我实际上不';不要使用CCSpriteBatchNode
我正在进行Cocos2d-x的移植,我基本上已经完成了这项工作,但有时我会遇到奇怪的CCAssert错误:Cocos2d x CCSpriteBatchNode断言发生在我实际上不';不要使用CCSpriteBatchNode,cocos2d-x,Cocos2d X,我正在进行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 her
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次)。我想知道——这是一个隐藏的框架逻辑?当我尝试向图层添加几个类似的精灵(四个导航按钮)时,它会执行一些转换吗?那么,在这种情况下,为什么它可以在cocos2-d上工作而没有错误呢?sprite不是使用批处理吗?你查过了吗?是的,我查过了。至少它没有任何引用、include、字段(甚至局部变量)等。使用CCBatchNode类设置断点,查看谁在调用
CCBatchNode
,它在CCSprite::addChild
中的名称是该类唯一链接的内容