救命

仿照书上和魔塔源码,实现了个加载地图和一个小人在原地走的功能。然后出了运行时错误,大概意思好像是指针悬垂之类的。错误锁定在两段代码。求大神指点。

CCAnimation *HelloWorld::createAnimationByDirection(HeroDirection direction)
{
CCTexture2D *heroTexture=CCTextureCache::sharedTextureCache()->addImage("hero.png");
CCSpriteFrame *frame0,*frame1,*frame2,*frame3;
frame0=CCSpriteFrame::createWithTexture(heroTexture,cocos2d::CCRectMake(32*0,32*direction,32,32));
frame1=CCSpriteFrame::createWithTexture(heroTexture,cocos2d::CCRectMake(32*1,32*direction,32,32));
frame2=CCSpriteFrame::createWithTexture(heroTexture,cocos2d::CCRectMake(32*2,32*direction,32,32));
frame3=CCSpriteFrame::createWithTexture(heroTexture,cocos2d::CCRectMake(32*3,32*direction,32,32));
CCArray* animFrames= new CCArray(4);
animFrames->addObject(frame0);
animFrames->addObject(frame1);
animFrames->addObject(frame2);
animFrames->addObject(frame3);
CCAnimation* animation =new CCAnimation();
animation->initWithSpriteFrames(animFrames,0.2f);
animFrames->release();
return animation;
}

上面是创建不同方向的动画函数。

CCTMXTiledMap *map=CCTMXTiledMap::create("0.tmx");
addChild(map);
walkAnimation=new CCAnimation*;
walkAnimation=createAnimationByDirection(kDown);
walkAnimation=createAnimationByDirection(kLeft);
walkAnimation=createAnimationByDirection(kRight);
walkAnimation=createAnimationByDirection(kUp);
CCSprite *heroSprite=CCSprite::createWithSpriteFrame((CCSpriteFrame *)(walkAnimation->getFrames()->objectAtIndex(0)));
heroSprite->setPosition(ccp(100,100));
addChild(heroSprite);
CCAnimate *animate=CCAnimate::create(walkAnimation);
heroSprite->runAction(CCRepeatForever::create(animate));
bRet = true;

上面代码是在init函数里添加的实现加载地图和一个小人原地走动的功能。我觉得错误出在上面代码第八行。