Processing of initial angle and Rotation Angle of cocos2d-x ccrotateto

Source: Internet
Author: User

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 }}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.