小弟自己的项目编译ANDROID , ECLIPSE编译通过,ANDROID手机上运行报 Get data from file(assets/XXX) failed
检查代码发现是Animatepacker.cpp中的 void AnimatePacker::loadAnimations(const std::string &path )
函数中报的错,
fullPathFromRelativePath函数我已经检查了cocos2dx 2.0.4 会返回正确地指针,应该不存在网络上所说的版本问题.
const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath)
{
return pszRelativePath;
}
Animatepacker中只要执行这一句parser.parse(pszPath),程序就会出错.
我检查了传入Animatepacker中的路径没有问题, 不知道各位大虾有没有解决办法,.真心谢过了。
附出错函数代码,红色执行会报:Get data from file(assets/XXX) failed
void AnimatePacker::loadAnimations(const std::string &path )
{
//const char *pszPath = CCFileUtils::sharedFileUtils()->CCFileUtils::fullPathFromRelativePath(path);
const char *pszPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(path.c_str());
CCSAXParser parser;
AnimateSaxDelegator delegator;
if (false == parser.init(“UTF-8”))
{
//TODO
return;
}
parser.setDelegator(&delegator);
parser.parse(pszPath);
//load plist
vector plists=delegator.plists;
for (unsigned int i=0;i<plists.size();i++)
{
string plistPath = CCFileUtils::sharedFileUtils()->CCFileUtils::fullPathFromRelativeFile(plists.c_str(), pszPath);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(plistPath.c_str());
}
//load animate
vector animates=delegator.animates;
CCArray *spriteFramesArray = new CCArray();
set animateNames;
for (unsigned int i=0;i<animates.size();i++)
{
Animate animate=animates;
vector spriteFrames=animate.spriteFrames;
for (unsigned int j=0;j<spriteFrames.size();j++)
{
animateNames.insert(spriteFrames);
CCSpriteFrame *spriteFrame=CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(spriteFrames.c_str());
spriteFramesArray->addObject(spriteFrame);
}
CCAnimation *animation=CCAnimation::animationWithSpriteFrames(spriteFramesArray,animate.delay);
CCAnimationCache::sharedAnimationCache()->addAnimation(animation,animate.name.c_str());
spriteFramesArray->removeAllObjects();
}
//record animate
for(unsigned int i=0;i<animates.size();i++){
Animate animate=animates;
nameToAnimateMap=animate;
}
//record plist
pathToPlistsMap=plists;
//record CCAnimate name
pathToNameMap=animateNames;
}