cocos2d-x实例学习(9)之CCCardinalSplineBy

前端之家收集整理的这篇文章主要介绍了cocos2d-x实例学习(9)之CCCardinalSplineBy前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
CCCardinalSplineBy概念
这个类是样条曲线动作,其创建函数CCCardinalSplineBy::create(float duration,cocos2d::CCPointArray *points,float tension);中duration是时间间隔,points是控制点列表,tension是松紧程度。tension==1时,样条线是分段直线。tension<1向外松弛弯曲,tension>1向内缩紧弯曲。By动作是以当前坐标为新坐标原点。

CCCardinalSplineBy示例–为同一组控制点实现不同的移动路径
  1. CCSize s = CCDirector::sharedDirector()->getWinSize();
  2. CCPointArray *array = CCPointArray::create(20);
  3. array->addControlPoint(ccp(0,0));
  4. array->addControlPoint(ccp(s.width/2-30,s.height-80));

  5. //
  6. // sprite 1 (By)
  7. // Spline with no tension (tension==0)
  8. CCCardinalSplineBy *action = CCCardinalSplineBy::create(3,array,0);
  9. CCActionInterval *reverse = action->reverse();
  10. CCFiniteTimeAction *seq = CCSequence::create(action,reverse,NULL);
  11. m_tamara->setPosition(ccp(50,50));
  12. m_tamara->runAction(seq);
  13. // sprite 2 (By)
  14. // Spline with high tension (tension==1)
  15. CCCardinalSplineBy *action2 = CCCardinalSplineBy::create(3,1);
  16. CCActionInterval *reverse2 = action2->reverse();
  17. CCFiniteTimeAction *seq2 = CCSequence::create(action2,reverse2,serif; font-size:12px; line-height:1.8em"> m_kathia->setPosition(ccp(s.width/2,serif; font-size:12px; line-height:1.8em"> m_kathia->runAction(seq2);
  18. 由于By动作是以当前坐标为新坐标原点,所以在draw函数里设置openGL的原点位置
  19. // move to 50,50 since the "by" path will start at 50,50
  20. kmGLPushMatrix();
  21. kmGLTranslatef(50,50,serif; font-size:12px; line-height:1.8em"> ccDrawCardinalSpline(m_pArray,100);
  22. kmGLPopMatrix();
  23. CCSize s = CCDirector::sharedDirector()->getWinSize();
  24. kmGLTranslatef(s.width/2,1,serif; font-size:12px; line-height:1.8em"> kmGLPopMatrix();
复制代码

效果图如下:

注:
CCPointArray解释 CCPointArray是一个包含控制点的数组,使用方法如上 原文链接:https://www.f2er.com/cocos2dx/339997.html

猜你在找的Cocos2d-x相关文章