void SpriteLayer::singleTouchEndsIn(CCPoint point)
{
CCLog("=============>%f, %f", point.x, point.y);
fire(point);
}
void SpriteLayer::fire(CCPoint point)
{
CCSprite * bullet = CCSprite::create("bullet.png", CCRectMake(0, 0, 20, 20));
......
......
bullet->runAction( CCSequence::create(
CCMoveTo::create(realMoveDuration, realDest),
CCCallFuncN::create(this,
callfuncN_selector(SpriteLayer::bulletMoveFinished)),
NULL) );
}
void SpriteLayer::bulletMoveFinished(CCNode* sender)
{
CCSprite *sprite = dynamic_cast(sender);
if (int cnt = this->getChildrenCount())
{
this->removeChild(sprite, true);
_bullet->removeObject(sprite);
}
}
```
代码片段如下:
当执行到this->removeChild(sprite, true);的时候程序爆出异常。
调试发现this指针的地址在fire函数和bulletMoveFinished函数中不一样,不明白哪里出了问题,求助各位的帮助,谢谢了!
bulletMoveFinished函数中你只生成一个精灵,没把它添加到this(场景、或者场景的layer,就看你的SpriteLayer继承于谁了)中,你直接remove当然会崩溃了。。。