我上传了我的源代码。是mac 版本的。打开运行一会后,就会出现人物播放动画的时候卡死了。有时候是放技能的时候,有时候是攻击时候卡死。还是水平太低了。实在是找不到问题所在,求大神帮我看看。在线等要源代码的可以留邮箱,这网站实在是传不上去
下面我是我部分的代码
void PlayerBase::initPlayerAnimation(std::string picName)
{
//初始角色化各种动画
isRunSkill = false;
std::string tempPicName = picName;
int length = tempPicName.length() - 7;
std::string newStr = tempPicName.substr(0,length);
int num = tempPicName.find(’_’);
setPlayerName(tempPicName.substr(0,num));
std::string attack = tempPicName.substr(0,num) + “_NAttack”;
std::string runstr = tempPicName.substr(0,num) + “_Walk”;
std::string hurtStr = tempPicName.substr(0,num) + “_Hurt”;
std::string KnockDownStr = tempPicName.substr(0,num) + “_KnockDown”;
std::string idleStr = tempPicName.substr(0,num) + “_Idle”;
std::string skill01Str = tempPicName.substr(0,num) + “_Skill01”;
std::string skill02Str = tempPicName.substr(0,num) + “_Skill02”;
std::string skill03Str = tempPicName.substr(0,num) + “_Skill03”;
//动画初始化
if(“Konan_Walk”!= runstr)
{
runAni = getAnimate(runstr.c_str());
runAni->retain();
pRunAction = CCRepeatForever::create(runAni);
pRunAction->retain();
pRunAction->setTag(1);
}
deadedAni = getAnimate(KnockDownStr.c_str());
deadedAni->retain();
deadedAction = CCRepeat::create(deadedAni,1);
deadedAction->retain();
attactAni = getAnimate(attack.c_str());
attactAni->retain();
attactAction = CCRepeat::create(attactAni, 1);
attactAction->retain();
injureAni = getAnimate(hurtStr.c_str());
injureAni->retain();
injureAction = CCRepeat::create(injureAni, 1);
injureAction->retain();
idle = getAnimate(idleStr.c_str());
idle->retain();
idleAction = CCRepeat::create(idle, 1);
idleAction->retain();
skill1Ani = getAnimate(skill01Str.c_str());
skill1Ani->retain();
skill1Action = CCRepeat::create(skill1Ani, 1);
skill1Action->retain();
if ("Deidara_Skill02" != skill02Str) {
skill2Ani = getAnimate(skill02Str.c_str());
skill2Ani->retain();
skill2Action = CCRepeat::create(skill2Ani, 1);
skill2Action->retain();
}
if(“Sai_Skill03” != skill03Str)
{
skill3Ani = getAnimate(skill03Str.c_str());
skill3Ani->retain();
skill3Action = CCRepeat::create(skill3Ani, 1);
skill3Action->retain();
}
KnockDownAni = getAnimate(KnockDownStr.c_str());
KnockDownAni->retain();
KnockDownAction = CCRepeat::create(KnockDownAni, 1);
KnockDownAction->retain();
addHpAni = getAnimate(“h_buff_effect”);
addHpAni->retain();
}
//攻击 ,技能 释放
void PlayerBase::attactKey(CCCallFuncN *callfuncN)
{
if (playerName == “Konan”) {
konanWalk->setVisible(false);
pSprite->setVisible(true);
}
if(isRunAttact == false %26%26 !isRunSkill)
{
isRunAttact = true;
runAnimate(attactAni,callfuncN,0);
}
}
void PlayerBase::skill1Key(CCCallFuncN *callfuncN)
{
if (isSkill1CD == false %26%26 isRunSkill == false) {
isSkill1CD = true;
isRunSkill = true;
if (playerName == "Konan") {
konanWalk->setVisible(false);
pSprite->setVisible(true);
}
//运行技能动画
runAnimate(skill1Ani,callfuncN,1);
//冷却相关
CCPoint parentPoint = ccp(-1000,-1000);
CCPoint childPoint = ccp(-1000,-1000);
scheduleOnce(schedule_selector(PlayerBase::skill1FreezeEnd), skill_1_FreezeTime);
if (isMainPlayer) {
parentPoint = getParent()->getParent()->getChildByTag(100)->getPosition();
childPoint = getParent()->getParent()->getChildByTag(100)->getChildByTag(1)->getPosition();
skillFreezeFun(102,skill_1_FreezeTime,ccp(parentPoint.x + childPoint.x,parentPoint.y + childPoint.y));
}
}
}
void PlayerBase::skill2Key(CCCallFuncN *callfuncN)
{
if (isSkill2CD == false %26%26 isRunSkill == false) {
isSkill2CD = true;
isRunSkill = true;
if (playerName == "Konan") {
konanWalk->setVisible(false);
pSprite->setVisible(true);
}
//运行2技能动画
runAnimate(skill2Ani,callfuncN,2);
scheduleOnce(schedule_selector(PlayerBase::skill2FreezeEnd), skill_2_FreezeTime);
//技能冷却
CCPoint parentPoint = ccp(-1000,-1000);
CCPoint childPoint = ccp(-1000,-1000);
if (isMainPlayer) {
parentPoint = getParent()->getParent()->getChildByTag(100)->getPosition();
childPoint = getParent()->getParent()->getChildByTag(100)->getChildByTag(2)->getPosition();
skillFreezeFun(103,skill_2_FreezeTime,ccp(parentPoint.x + childPoint.x,parentPoint.y + childPoint.y));
}
}
}
void PlayerBase::skill3Key(CCCallFuncN *callfuncN)
{
if (isSkill3CD == false %26%26 isRunSkill == false) {
isSkill3CD = true;
isRunSkill = true;
if (playerName == “Konan”) {
konanWalk->setVisible(false);
pSprite->setVisible(true);
}
//运行技能3
runAnimate(skill3Ani,callfuncN,3);
scheduleOnce(schedule_selector(PlayerBase::skill3FreezeEnd), skill_3_FreezeTime);
//技能冷却
CCPoint parentPoint = ccp(-1000,-1000);
CCPoint childPoint = ccp(-1000,-1000);
if (isMainPlayer) {
parentPoint = getParent()->getParent()->getChildByTag(100)->getPosition();
childPoint = getParent()->getParent()->getChildByTag(100)->getChildByTag(3)->getPosition();
skillFreezeFun(104,skill_3_FreezeTime,ccp(parentPoint.x + childPoint.x,parentPoint.y + childPoint.y));
}
}
}
void PlayerBase::runFreezeEnd(int ProgressinTag ,int itemTag ,int childTag)
{
// CCMenu *hPItem = (CCMenu *)getParent()->getParent()->getChildByTag(itemTag);
// ((CCMenuItem *)hPItem->getChildByTag(childTag))->setEnabled(true);
CCProgressTimer *skillFreezePro =(CCProgressTimer *)getParent()->getParent()->getChildByTag(ProgressinTag);
skillFreezePro->setVisible(false);
skillFreezePro->stopAllActions();
}
void PlayerBase::skill1FreezeEnd(float dt)
{
if(isMainPlayer)
runFreezeEnd(102,100,1);
isSkill1CD = false;
}
void PlayerBase::skill2FreezeEnd(float dt)
{
if(isMainPlayer)
runFreezeEnd(103,100,2);
isSkill2CD = false;
}
void PlayerBase::skill3FreezeEnd(float dt)
{
if(isMainPlayer)
runFreezeEnd(104,100,3);
isSkill3CD = false;
}
void PlayerBase::runAnimate(CCAnimate *animate,CCCallFuncN callfuncN,int selectRect)
{
//停止跑动,停止休息动画,停止左右跑
this->stopActionByTag(1);
pSprite->stopActionByTag(1);
pSprite->stopActionByTag(2);
pSprite->stopActionByTag(3);
//播放动画
CCAction skillAction = CCSequence::create(CCRepeat::create(animate,1),callfuncN,NULL);
if (selectRect == 0) {
skillAction->setTag(10);
}else
{
if (pSprite->getActionByTag(10)) {
pSprite->stopActionByTag(10);
}
}
pSprite->runAction(skillAction);
//纪录当前播发的动画
curAni = animate;
//纪录当前选择的碰撞矩形
this->selectRect = selectRect;
}
void PlayerBase::skillFreezeFun(int ProgressinTag ,float freezeTime, CCPoint freezeItemPos)
{
if (isMainPlayer) {
//创建冷却进度条
CCProgressTo *to1 = CCProgressTo::create(freezeTime, 100);
CCProgressTimer *HpFreezePro =(CCProgressTimer *)(this->getParent()->getParent()->getChildByTag(ProgressinTag));
HpFreezePro->setPosition(freezeItemPos);
HpFreezePro->setVisible(true);
HpFreezePro->runAction(CCRepeat::create(to1,1));
}
}
/////////////////////////////////////////////////////////
XiaoYing::XiaoYing(const char *picName,bool setFlipX ,int camp ,bool isHaro):PlayerBase(picName,setFlipX,camp,isHaro)
{
scheduleUpdate();
XiaoYingInit();
CCLayerColor *layerColor = CCLayerColor::create(ccc4(0, 0, 0, 255), 30, 30);
layerColor->setPosition(ccp(-40, -10));
schedule(schedule_selector(XiaoYing::myAIControl), 0.5f);
myCircle = new CCCircle();
}
XiaoYing::~XiaoYing()
{
}
void XiaoYing::XiaoYingInit()
{
setPlayerAttactBodyPoint(ccp(15,-10));
setPlayerAttactBodySize(CCSize(30, 20));
}
void XiaoYing::myAIControl(float dt)
{
if (!isMainPlayer %26%26 !isRunSkill) {
//找到了攻击目标并移动到攻击目标
PlayerBase * tagetPlayer = moveToTaget();
if (tagetPlayer != NULL) {
//执行不需要碰撞检测的技能
if(noNeedCrachChackSkill())
return;
//检测和目标是否碰撞了
if(crachChack(tagetPlayer))
{
//选择要释放的技能
if(!selectSkill())
{
if (attact()) {
CCLOG("%s 普通攻击",getPlayerName().c_str());
}
}
}
}
}
if(isRunSkill || isRunAttact)
{
//扣血
vsSubBlood();
}
}
PlayerBase * XiaoYing::moveToTaget()
{
//查找要攻击的目标
PlayerBase* fPlayer = findNearest();
if (fPlayer != NULL)
{
//CCPoint offsetPoint = getOffsetPoint();
CCPoint offsetPoint = calculateMovePoint(fPlayer);
// run(ccp(fPlayer->getPosition().x - getOffsetPoint().x ,fPlayer->getPosition().y - getOffsetPoint().y ));
//run(ccp(fPlayer->getPosition().x - getOffsetPoint().x ,fPlayer->getPosition().y ));
run(offsetPoint);
return fPlayer;
}
CCLOG(“没有找到攻击目标”);
return NULL;
}
bool XiaoYing::crachChack(PlayerBase tagetPlayer)
{
//设定选择技能碰撞矩形(等下需要修改)
initAttactRect(ccp(2,-10), ccp(-25,-10), CCSize(27,15),
ccp(-22,-15),ccp(-22,-15),CCSize(45,15),
ccp(2,-10), ccp(-25,-10), CCSize(27,15),
ccp(2,-10), ccp(-25,-10), CCSize(27,15));
CCRect myRect = getPlayerAttactBodyRect();
CCRect vsRect = tagetPlayer->getPlayerBodyRect();
if(myRect.intersectsRect(vsRect))
{
return true;
}
return false;
}
bool XiaoYing::noNeedCrachChackSkill()
{
if (!isSkill1CD %26%26 myAttribute.hp < 900)
{
skill1Key(CCCallFuncN::create(this, callfuncN_selector(XiaoYing::judgeWhetherStopRunAnimate1)));
return true;
}
else if (!isSkill3CD)
{
if(chackNearHavePeople())
{
skill3Key(CCCallFuncN::create(this, callfuncN_selector(XiaoYing::judgeWhetherStopRunAnimate3)));
return true;
}
}
return false;
}
bool XiaoYing::chackNearHavePeople()
{
PlayerBase fPlayer = findNearest();
myCircle->setMCenter(getPosition());
myCircle->setMRadius(200);
CCRect vsRect = fPlayer->getPlayerBodyRect();
if(myCircle->intersectsRect(vsRect))
return true;
return false;
}
bool XiaoYing::selectSkill()
{
if (!isSkill2CD)
{
skill2Key(CCCallFuncN::create(this, callfuncN_selector(XiaoYing::judgeWhetherStopRunAnimate2)));
return true;
}
return false;
}
bool XiaoYing::attact()
{
if(!isRunAttact)
{
attactKey(CCCallFuncN::create(this, callfuncN_selector(XiaoYing::judgeWhetherStopRunAnimate)));
return true;
}
return false;
}
void XiaoYing::vsSubBlood()
{
//设定扣血碰撞矩形
initAttactRect(ccp(15,-10),ccp(-40,-10), CCSize(30,20),
ccp(-45,-30),ccp(-45,-30),CCSize(90,30),
ccp(15,-10),ccp(-40,-10), CCSize(30,20),
ccp(2,-10), ccp(-25,-10), CCSize(27,15));
int currentFrame = getCurFrameCount();
if (checkRepeat != currentFrame )
{
checkRepeat = currentFrame;
//检测碰撞
CCArray* vsAllPlayer;
vsAllPlayer = getAllvsPlayer();
int allNum = vsAllPlayer->count();
for (int i = 0; i < allNum; i++)
{
PlayerBase *vs = (PlayerBase *)vsAllPlayer->objectAtIndex(i);
CCRect myRect;
myRect = getPlayerAttactBodyRect();
CCRect vsRect = vs->getPlayerBodyRect();
if (myRect.intersectsRect(vsRect) %26%26 selectRect == 0 %26%26 (currentFrame == 0 || currentFrame == 3 || currentFrame == 7 || currentFrame == 10)) {
vs->minusBlood(myAttribute.baseAttact);
}else if(selectRect == 1 %26%26 currentFrame == 8){
this->RecoveryOfBlood(5,50);
}else if (myRect.intersectsRect(vsRect) %26%26 selectRect == 2){
if(currentFrame == 3 || currentFrame == 5 ||currentFrame == 7 || currentFrame == 9 || currentFrame == 10)
vs->minusBlood(100);
}else if(selectRect == 3 %26%26 currentFrame == 10){
myAttribute.baseAttact = 70;
showPowerBuffEffect();
}
}
}
}
void XiaoYing::showPowerBuffEffect()
{
CCSpriteFrameCache *spriteFrameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
CCSprite *BuffSpri = CCSprite::createWithSpriteFrame(spriteFrameCache->spriteFrameByName(“p_buff_effect_01.png”));
addChild(BuffSpri,1000,1000);
BuffSpri->runAction(CCRepeatForever::create(getAnimate(“p_buff_effect”)));
CCAction *action = CCSequence::create(CCDelayTime::create(10.0f),CCCallFunc::create(this, callfunc_selector(XiaoYing::powerBuffEnd)),NULL);
CCNode *node = CCNode::create();
node->setTag(1001);
addChild(node);
node->runAction(action);
}
void XiaoYing::powerBuffEnd()
{
myAttribute.baseAttact = 20;
removeChildByTag(1000, true);
removeChildByTag(1001, true);
}
void XiaoYing::judgeWhetherStopRunAnimate(cocos2d::CCNode *pNode)
{
judge();
}
void XiaoYing::judgeWhetherStopRunAnimate1(cocos2d::CCNode *pNode)
{
judge();
}
void XiaoYing::judgeWhetherStopRunAnimate2(cocos2d::CCNode *pNode)
{
judge();
}
void XiaoYing::judgeWhetherStopRunAnimate3(cocos2d::CCNode *pNode)
{
judge();
}
void XiaoYing::judge()
{
isRunSkill = false;
isRunAttact = false;
isRunArriveTagetPoint = true;
CCRepeatForever *repeatForever = CCRepeatForever::create(idle);
repeatForever->setTag(3);
pSprite->runAction(repeatForever);
}


