CCMoveBy values on update()

Posted by Jose M Pan on Game Development See other posts from Game Development or by Jose M Pan
Published on 2013-09-12T22:05:51Z Indexed on 2013/10/30 10:24 UTC
Read the original article Hit count: 146

Filed under:

Hope you can help me. This is my problem: I have a scheduled update, here I track the movements of my objects (sprites), I move them with CCMoveBy, and I need to constantly update the zOrder. For setting the zOrder I've made a setZOrder(), which it takes the actual position of the sprite. And here is the problem, I get all the X and Y values AFTER the object is in the target. I know I get the values after the object is in the new position because I've made a CCLog. I can read all the values from the sprite, only when it's in the new position, so everything is well sorted only when the objects are not moving. How can I get the CCMoveBy values on every tick update? (or how can I get the CCMoveBy values in "real-time"?)

Thanks a lot in advance,

Here is an idea of my code.

this->schedule(schedule_selector(Game::update));

void Game::update(float dt)
{
   setZOrder();
   moveObjects();
}

void Game::setZOrder()
{
  //This function takes the X and Y position and the row and column where the sprite is. Is working good. But I'm getting the "move" action values, after the object is in place.
}

void Game::moveObjects()
{
   for (i=0; i < numChildren; i++)
   {
     CCActionInterval* move = CCMoveBy::create(targetPoint, time);
     object[i]->runAction(move);
   }
}

© Game Development or respective owner

Related posts about cocos2d-x