Link: http://blog.csdn.net/zhangxaochen/article/details/8058590
Suppose there is such code (hello is a sprite ):
hello->setRotation(720);hello->runAction( CCRotateTo::create(2, 720) );
Set the sprite's initial angle to 720 degrees, and then run "ccrotateto: Create (2,720 )". At first glance, from 720 degrees to 720 degrees, it should be static; but in fact, this sprite rotates 360 degrees clockwise.
It's funny...
See the ccactioninterval. cpp line: 810 code:
void CCRotateTo::startWithTarget(CCNode *pTarget){ CCActionInterval::startWithTarget(pTarget); m_fStartAngle = pTarget->getRotation(); if (m_fStartAngle > 0){ m_fStartAngle = fmodf(m_fStartAngle, 360.0f); } else{ m_fStartAngle = fmodf(m_fStartAngle, -360.0f); } m_fDiffAngle = m_fDstAngle - m_fStartAngle; if (m_fDiffAngle > 180){ m_fDiffAngle -= 360; } if (m_fDiffAngle < -180){ m_fDiffAngle += 360; }}
If your sprite has a rotateto action, getrotation will get the rotation and the modulo of 360. So the previous 720 ° is changed to 0.
Then, the function judges the rotation angle: 720-0 (this 0 is the previous 720) = 720, greater than 180 °, So-= 360, get the rotation angle 360 °.
So we can explain the problem that Hello actually rotates 360 ° in the first example.
It may be because I am too light-minded. I really don't know the physical meaning of this function for the initial angle and rotation angle. However, since rotateto is not easy to use, avoid using it as much as possible. Rotateby should have no logic problems.
Link: http://blog.csdn.net/zhangxaochen/article/details/8058590
{Over }}