S
S
slon_ru2014-01-24 16:03:11
Cocos2d
slon_ru, 2014-01-24 16:03:11

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ов.
}

ps Found what's the matter - you need to do walkLeft->retain(); otherwise it is autoreleased after exiting the init,
but now how to kill the topic?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2014-01-24
@AMar4enko

Take the trouble to properly arrange the tags of the source codes. Nobody will read this mess.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question