bool CCNewGame::init(){
bool bRet = false;
do 
{
                CC_BREAK_IF(!CCLayer::init());
//添加主角精灵
CCTexture2D * pTextTure = CCTextureCache::sharedTextureCache()->addImage("dragon.png");
this->m_pSpriteBatch = CCSpriteBatchNode::createWithTexture(pTextTure,10);
this->addChild(m_pSpriteBatch,1,1);
this->m_pFlyActionArray = CCArray::create();
for (int i=0;i<8;i++){
CCAnimation * pAnimation = CCAnimation::create();
CC_BREAK_IF(!pAnimation);
pAnimation->setDelayPerUnit(0.15f);
for (int j=0;j<10;j++){
CCSpriteFrame * frame = CCSpriteFrame::createWithTexture(this->m_pSpriteBatch->getTexture(),
CCRectMake(75*j,70*i,75,70));
CC_BREAK_IF(!frame);
pAnimation->addSpriteFrame(frame);
}
CCAnimate * anim = CCAnimate::create(pAnimation);
this->m_pFlyAction = CCRepeatForever::create(anim);
this->m_pFlyActionArray->addObject(m_pFlyAction);
}
CCSpriteFrame * frame1 = CCSpriteFrame::createWithTexture(this->m_pSpriteBatch->getTexture()
,CCRectMake(75*0,70*0,75,70));
CC_BREAK_IF(!frame1);
this->m_pDragon = CCSprite::createWithSpriteFrame(frame1);
this->m_pDragon->setPosition(ccp(160,240));
this->m_pFlyAction = (CCAction *)m_pFlyActionArray->objectAtIndex(0);
this->m_pDragon->runAction(m_pFlyAction);
this->addChild(m_pDragon,0,123);
this->setTouchEnabled(true);
bRet = true;
} while (0);
return bRet;
}void CCNewGame::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){
CCPoint p = pTouch->getLocation();
CCPoint nowPoint = this->getChildByTag(123)->getPosition();
CCPoint moveVector = ccpSub(p, nowPoint);
float distance = ccpLength(moveVector);
float moveAngle = ccpToAngle(moveVector);
float cocosAngle = CC_RADIANS_TO_DEGREES(-1 * moveAngle);
float moveDuration = distance/(480.0/3.0);
cocosAngle += 23;
if (cocosAngle <0){
cocosAngle += 360;
}
int animNum = (int)((cocosAngle)/45);
this->getChildByTag(123)->stopAction(this->m_pFlyAction);
this->m_pFlyAction = (CCAction *)this->m_pFlyActionArray->objectAtIndex(animNum);///报错是这一步
this->getChildByTag(123)->runAction(this->m_pFlyAction);
this->getChildByTag(123)->runAction(CCMoveTo::create(moveDuration,p));
}

解决方案 »

  1.   

    主要就是画面上一条龙,龙的动画一共有8个,正好向8个方向飞的动画,存储到了CCArry里面,在init()方法里面怎么用都可以,但是一到ccTouchEnd()里面就报错了,成员对象在ccTouch()里面可以调用啊,但是为什么内存溢出呢,可以调试通过,我一点画面,想飞行就停止运行,应该是内存的问题吧.求解答
      

  2.   

    应该是因为你在init里面创建的array没有retain, 你可以retain一下试试
      

  3.   

    对啊,没有申请内存空间,所以内存crash了,后来弄好了,今天才想起来提问了,结贴了哈~