码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-05-18 07:02:31      阅读:250      评论:0      收藏:0      [点我收藏+]

标签:cocos2d-x   cocos2dx3.0   

(原文地址: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);

实现精灵沿着圆形轨迹运动,布布扣,bubuko.com

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

标签:cocos2d-x   cocos2dx3.0   

原文地址:http://blog.csdn.net/while0/article/details/26008033

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!