Hello cocos2d-x, I get some questions with action. In my game I create a new action with CCMoveTo.when it run to end, the position is wrong. I found it will be set to the start pos and other action such as CCScaleTo, CCFadein .etc. So I check the source code and print some log. Finally I found that in the CCActionInterval::step(ccTime dt) method, the update will be called, but the m_elapsed was wrong. Because the last if conditition would be invoked and the m_elapsed is 0. Here is the log
——————time = 0.436000, elapsed = 0.109000, duration = 0.250000
pos.x = 437.436005, pos.y = 325.720001
——————time = 0.500000, elapsed = 0.125000, duration = 0.250000
pos.x = 437.500000, pos.y = 295.000000
——————time = 0.560000, elapsed = 0.140000, duration = 0.250000
pos.x = 437.559998, pos.y = 266.200012
——————time = 0.624000, elapsed = 0.156000, duration = 0.250000
pos.x = 437.623993, pos.y = 235.479996
——————time = 0.684000, elapsed = 0.171000, duration = 0.250000
pos.x = 437.683990, pos.y = 206.679993
——————time = 0.748000, elapsed = 0.187000, duration = 0.250000
pos.x = 437.747986, pos.y = 175.959991
——————time = 0.872000, elapsed = 0.218000, duration = 0.250000
pos.x = 437.872009, pos.y = 116.439980
——————time = 0.936000, elapsed = 0.234000, duration = 0.250000
pos.x = 437.936005, pos.y = 85.719978
CCActionInterval::step m_elpased -= m_fDuration, m_continue = 0.250000, m_Total = 0.250000, m_elapsed = 0.250000, m_fDuration = 0.250000
——————time = 0.000000, elapsed = 0.000000, duration = 0.250000
and the code
void CCActionInterval::step(ccTime dt) { if (m_bFirstTick) { m_bFirstTick = false; m_elapsed = 0; m_continue = 0; CCLOG("CCActionInterval::step(ccTime dt) m_elpased = 0"); } else { m_elapsed += dt; m_continue += dt; } if(m_continue <= m_Total && m_elapsed >= m_fDuration) { CCLOG("CCActionInterval::step(ccTime dt) m_elpased -= m_fDuration, m_continue = %f, m_Total = %f, m_elapsed = %f, m_fDuration = %f",m_continue, m_Total, m_elapsed, m_fDuration); m_elapsed -= m_fDuration; } // update(min(1, m_elapsed/m_fDuration)); update(1 > m_elapsed/m_fDuration ? m_elapsed/m_fDuration : 1); }
So how to solve this problem and maybe modify the statement be “m_elapsed > m_fDuration” ?