I am new to cocos2dx. I am trying to convert my game from cocos2d to cocos2dx.
I start from this project (http://www.raywenderlich.com/32045/how-to-use-animations-and-sprite-sheets-in-cocos2d-2-x)
I got Access violation reading location.
I run the debug mode. The error is this line *bear~~>runAction;
I have no idea about this because it works perfectly when this line is written on init.
I paste my code here.
on header file, i have declared these pointers.
cocos2d::CCAction ***walkAction;
cocos2d::CCAction *moveAction;
cocos2d::CCSprite**bear;
cpp file:
<pre>
bool HelloWorld::init {
if) {
return false;
}
CCMenuItemImage *pCloseItem = CCMenuItemImage::create);
// Place the menu item bottom-right conner.
pCloseItem~~>setPosition~~>getWinSize.width~~ 20, 20));
// Create a menu with the “close” menu item, it’s an auto release object.
CCMenu* pMenu = CCMenu::create;
pMenu~~>setPosition;
// Add the menu to HelloWorld layer as a child layer.
this~~>addChild;
// From Anim Bear cocos2d-iphone
*moveAction = NULL;
*walkAction = NULL;
this~~>setTouchEnabled;
*bearMoving = false;
CCSize winSize = CCDirector::sharedDirector~~>getWinSize ;
CCSpriteFrameCache cache = CCSpriteFrameCache::sharedSpriteFrameCache;
cache->addSpriteFramesWithFile;
cocos2d::CCSpriteBatchNodespriteSheet = CCSpriteBatchNode::batchNodeWithFile;
this~~>addChild;
CCArray walkAnimFrames = new CCArray;
for {
char temp[30];
sprintf;
CCSpriteFrame frame = cache~~>spriteFrameByName;
walkAnimFrames->addObject;
}
CCAnimation *walkAnim = CCAnimation::animationWithSpriteFrames;
*walkAction = CCRepeatForever::actionWithAction(CCAnimate::actionWithAnimation(walkAnim));
*bear = CCSprite::spriteWithSpriteFrameName;
*bear~~>setPosition);
//_bear~~>runAction(*walkAction);
spriteSheet~~>addChild;
return true;
}
// cpp with cocos2d-x
void HelloWorld::ccTouchesEnded
{
// Choose one of the touches to work with
CCTouch* touch = );
CCPoint location = touch~~>locationInView;
location = CCDirector::sharedDirector~~>convertToGL;
// Set up initial location of projectile
CCSize winSize = CCDirector::sharedDirector~~>getWinSize;
float bearVelocity = winSize.width / 3.0;
CCPoint moveDifference = ccpSub);
float distanceToMove = ccpLength;
float moveDuration = distanceToMove / bearVelocity;
if {
*bear->setFlipX;
}
else {
*bear~~>setFlipX;
}
*bear->stopAction;
if {
*bear~~>runAction;
}
*moveAction = cocos2d::CCSequence::create(
cocos2d::CCMoveTo::actionWithDuration(moveDuration, location),
cocos2d::CCCallFuncN::create(this, callfuncN_selector(HelloWorld::bearMoveEnded)),
NULL);
*bear~~>runAction;
*bearMoving = true;
}
void HelloWorld::bearMoveEnded
{
*bear~~>stopAction;
*bearMoving = false;
}