Marija Milosevic
Marija Milosevic

Reputation: 516

Cocos2d-x runAction Error

Okay, so I want my cat sprite to move up and down onClick of two (UP and DOWN) buttons. I'm a beginner in cocos2d-x. So, in mygame.h i have a global declaration of the sprite cat:

cocos2d::Sprite *cat;

In one function i create a new scene and add a cat in it.

    cat = Sprite::create("cat.png");
cat->setScale(0.2);
cat->setPosition(0, 190);//(Director::getInstance()->getVisibleOrigin().x + 50,       Director::getInstance()->getVisibleSize().height / 2);
layer->addChild(cat);
playscene->addChild(cat);

In another function(button callback) i have this code:

    void HelloWorld::down(Object* pSender){
CCActionInterval* down = CCMoveBy::create(1.0f, Point(0.0, -20.0));
cat->runAction(down);
}

And everything's ok untill i press the up or down button. It throws an error on the cat->runAction(down); line. When i exemine the variable cat, it looks like I cant get to the position parameters. Its a memory read error..

Upvotes: 1

Views: 741

Answers (2)

Hitesh Rajyaguru
Hitesh Rajyaguru

Reputation: 87

In cocos2dx 3.0 you can write direct in runaction for any sprite.

spriteName->runAction(Sequence::create(MoveBy::create(1.0f,Point(398,565)),NULL));

Upvotes: 1

microslop
microslop

Reputation: 666

It looks like you are mixing Cocos2D-X 2.x API's with Cocos2D-X 3.0 ones. I'm taking a stab in the dark guess and saying it looks like you're trying to use 3.0. You will need to change the following line:

CCActionInterval* down = CCMoveBy::create(1.0f, Point(0.0, -20.0));

To:

ActionInterval* down = MoveBy::create(1.0f, Point(0.0, -20.0));

Upvotes: 0

Related Questions