Answer the question
In order to leave comments, you need to log in
How to save a chain of actions in cocos2dx?
Good afternoon!
I am trying to master cocos2dx, trying c++. I'm new to both.
I want to collect several actions - character movement + animation at the same time, plus a callback at the end of the chain. Something like this -Sequence m_seq= Sequence (spawn(animate,moveto),moveDone,null); I save the pointer to the chain of actions as a member of the class, which would then be called in onkeypresse (); Everything works in inite, but an empty list comes to keypress, what am I doing wrong here? Thank you!
helloworld.h
{
Animation * animWalk; //спрайты
Animate* actAnimWalk; //1е действие (a1)
Sprite *mouse; //спрайт
MoveBy* actMove; //2е действие (a2)
CallFuncN* actMoveDone; //3е действие (a3)
Sequence *walkRight, *walkLeft; //цепочка
}
bool HelloWorld::init()
{ //...выше была загрузка спайтов в animWalk
actMoveDone=CallFuncN::create(CC_CALLBACK_1(HelloWorld::spriteMoveFinished,this)); //init a3
actAnimWalk=Animate::create(animWalk); //init a1
actMove = MoveBy::create (0.9f , Point (-20,0)); //init a2
Spawn * actAnimWalkMove = Spawn::create(actAnimWalk,actMove,NULL); // сохраняем а1 и а2 как параллельные действия и а3 как последовательное(а3 сточкой ниже).
walkLeft= Sequence::create(actAnimWalkMove,actMoveDone,NULL); .сохраняем всю цепочку.
//тут работает.
mouse->runAction(walkLeft); //вызываем цепочку.
}
void HelloWorld::onKeyPressed (EventKeyboard::KeyCode keyCode,Event* event)
{
if (KeyCode==KeyCode::KEY_A)
mouse->runAction(walkLeft); // тут нет. в walkLeft список nullptrов.
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question