您的位置:首页 > 其它

实现精灵沿着圆形轨迹运动

2017-04-27 12:02 267 查看
(原文地址:http://blog.csdn.net/while0/article/details/26008033)

使用样条曲线模拟圆形轨迹,当切割数量足够大时,逐渐逼近圆形。

Point pos(100, 100); //start point
m_animSprite->setPosition(pos);

int count = 8;
float angle = 360.f/count;
float radius = 50.f;
auto array = PointArray::create(count + 1);
Point pt0(radius, 0.f), pt;
for (int i = 0; i <= count; i++)
{
pt = pt0 + Point(-radius, 0);
array->addControlPoint(pt);
pt0 = pt0.rotateByAngle(Point::ZERO, CC_DEGREES_TO_RADIANS(angle));
}
auto action = CardinalSplineBy::create(3, array, 0);
auto seq = RepeatForever::create(action);
m_animSprite->runAction(seq);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐