旋转转盘 算法


/*
  转盘旋转 先加速 后减速
  inallTime 总共旋转时间
  inallAngle 总共旋转角度
  times 时间份数
*/
void HelloWorld::RotateTurntable(CCSprite* pSprite,float inallTime,float inallAngle,int times)
{
	CCArray* actions = CCArray::create();

	float inallRadian = (inallAngle / 180.0) * M_PI;
	float offsetTime = inallTime / times;
	float offsetAngle =  inallRadian / (atan(inallTime / 2) - atan(-inallTime / 2)); 
	float startTime = - inallTime / 2;
	while (startTime <= inallTime / 2)
	{

		float angle = (atan(startTime + offsetTime) - atan(startTime)) * offsetAngle * 180 / M_PI;
		startTime += offsetTime;

		CCActionInterval* actionTo = CCRotateBy::create(offsetTime, angle);
		actions->addObject(actionTo);
	}
	pSprite->runAction(CCSequence::create(actions));
}


你可能感兴趣的:(Cocos2d-x学习)