Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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");
    this->addChild(spreetsheet);

CCArray *bearArray = new CCArray();
     for(int i = 1; i <= 8; i++)
{
        char name[32] = {0};
         sprintf(name, "bear%d.png",i);
        bearArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name));
}
    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);
spreetsheet->addChild(bear);

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).

share|improve this question
    
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

1 Answer 1

up vote 2 down vote accepted

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");
    this->addChild(spreetsheet);

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

    CCAnimation *walkAnim = CCAnimation::createWithSpriteFrames(bearArray, 0.1f);
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCSprite *bear = CCSprite::createWithSpriteFrameName("bear1.png");
    bear->setPosition(ccp(size.width/2, size.height/2));
    CCAction *walkAction = CCRepeatForever::create(CCAnimate::create(walkAnim));
    bear->runAction(walkAction);
    spreetsheet->addChild(bear);
share|improve this answer
    
wow, it works, I referred Objective C code for the same, It seems most the method name are 'create' instead of fully descriptive names –  pradeep Feb 28 at 7:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.