sprite 根据相对弧度旋转

void MainLayer::ccTouchesEnded(CCSet *pTouches, CCEvent*pEvent)

{

   CCSize size=CCDirector::sharedDirector()->getWinSize();

    CCSetIterator it = pTouches->begin();

    CCTouch* touch = (CCTouch*)(*it);

       CCPoint location = touch->getLocation();

    CCNode* s = getChildByTag(kTagSprite);

    s->stopAllActions();

    s->runAction( CCMoveTo::create(1, ccp(location.x, location.y) ) );

    CCLog("xx===%f,yy===%f",location.x, location.y);

    CCLog("w===%f,h===%f",size.width, size.height);

    float o = location.x - s->getPosition().x;

    float a = location.y - s->getPosition().y;

     CCLog("w===%f,h===%f",a, o);

    float at = (float) CC_RADIANS_TO_DEGREES( atanf( o/a) );

    CCLog("%f",at);

//    CCLog("%f",fabs(at));

    if( a < 0 )

    {

        if(  o < 0 )

            at = 180 + fabs(at);

        else

            at = 180 - fabs(at);    

    }

    s->runAction( CCRotateTo::create(1, at) );

}

 

posted on 2013-04-14 10:31  jack_yan  阅读(230)  评论(0编辑  收藏  举报