# Sprite Animation using cocos2dx 2.0.2

I am trying to implement sprite animation using coco2dx. I have tried several demos, but all of them are same. While I tried, getting violation error in my code.

CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("AnimBear.plist");
CCSpriteBatchNode *spreetsheet = CCSpriteBatchNode::create("AnimBear.png");

CCArray *bearArray = new CCArray();
for(int i = 1; i <= 8; i++)
{
char name[32] = {0};
sprintf(name, "bear%d.png",i);
}
CCAnimation *walkAnim = CCAnimation::animationWithSpriteFrames(bearArray, 0.1f);
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite *bear = CCSprite::spriteWithSpriteFrameName("bear1.png");
bear->setPosition(ccp(size.width/2, size.height/2));
CCAction *walkAction = CCRepeatForever::actionWithAction(CCAnimate::actionWithAnimation(walkAnim));
bear->runAction(walkAction);


Error is coming in first line while we passing plist refrence. I am using Visual Basic 2010 and put both files in Resource folder (png and plist).

• which line causes the access violation? – Heisenbug Sep 11 '12 at 11:03
• first line while passing reference of plist. – Lalit Chattar Sep 11 '12 at 11:31
• I will assume you are using Visual Studio 2010 and running a Visual C++ vcproj project. I would check the output compile directory i.e "Debug.Win32" and check if the plist file is in the root. – Eat at Joes Sep 11 '12 at 16:02
• @eat at joes :: i did not get it. what do i have to do? – Lalit Chattar Sep 12 '12 at 6:09
• I'm just saying it's likely a resource that can't be found. The project properties page will allow you to define resource folders but you could also physically drop this plist file in the same directory as your executable. But without more information this is just my guess. – Eat at Joes Sep 26 '12 at 5:13

I have this code working in cocos2dx 2.0.3, also make sure that you've added the plist and png file to your project, sometimes visual studio can be a bit funny about resources.

   CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("AnimBear.plist"    );
CCSpriteBatchNode *spreetsheet = CCSpriteBatchNode::create("AnimBear.png");

CCArray *bearArray = new CCArray();
for(int i = 1; i <= 8; i++)
{
char name[32] = {0};
sprintf(name, "bear%d.png",i);