Search code examples
c++windows-phone-8visual-studio-2013cocos2d-x

Unhandeled exception when adding sprite in cocos2d in Visual Studio


Unhandled exception at 0x0096348B in HelloWorld.exe: 0xC0000005: Access violation reading location 0x00000000.

this is the error i get when trying to use a Sprite i added.

CCSprite *sprite = CCSprite::spriteWithFile("Untitled.png" );
sprite->setAnchorPoint(CCPointZero);
this->addChild(sprite, -1);

Error is at first line

Thanks for your help.

am using Visual Studio 2013


Solution

  •         Try! this it works for me.
      CCSize screenSize   = CCDirector::sharedDirector()->getVisibleSize();
            pointOrigin  = CCDirector::sharedDirector()->getVisibleOrigin();
            x = screenSize.width;
            y = screenSize.height;
    
    
        CCSprite* sprite=CCSprite::create("icon.png");
            sprite->setPosition(ccp(x/2,y/2));
            addChild(sprite,1);