CCCardinalSplineBy概念
这个类是样条曲线动作,其创建函数CCCardinalSplineBy::create(float duration,cocos2d::CCPointArray *points,float tension);中duration是时间间隔,points是控制点列表,tension是松紧程度。tension==1时,样条线是分段直线。tension<1向外松弛弯曲,tension>1向内缩紧弯曲。By动作是以当前坐标为新坐标原点。
CCCardinalSplineBy示例–为同一组控制点实现不同的移动路径
- CCSize s = CCDirector::sharedDirector()->getWinSize();
- CCPointArray *array = CCPointArray::create(20);
- array->addControlPoint(ccp(0,0));
- array->addControlPoint(ccp(s.width/2-30,s.height-80));
-
- //
- // sprite 1 (By)
- // Spline with no tension (tension==0)
- CCCardinalSplineBy *action = CCCardinalSplineBy::create(3,array,0);
- CCActionInterval *reverse = action->reverse();
- CCFiniteTimeAction *seq = CCSequence::create(action,reverse,NULL);
- m_tamara->setPosition(ccp(50,50));
- m_tamara->runAction(seq);
- // sprite 2 (By)
- // Spline with high tension (tension==1)
- CCCardinalSplineBy *action2 = CCCardinalSplineBy::create(3,1);
- CCActionInterval *reverse2 = action2->reverse();
- 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);
- 由于By动作是以当前坐标为新坐标原点,所以在draw函数里设置openGL的原点位置
- // move to 50,50 since the "by" path will start at 50,50
- kmGLPushMatrix();
- kmGLTranslatef(50,50,serif; font-size:12px; line-height:1.8em"> ccDrawCardinalSpline(m_pArray,100);
- kmGLPopMatrix();
- CCSize s = CCDirector::sharedDirector()->getWinSize();
- kmGLTranslatef(s.width/2,1,serif; font-size:12px; line-height:1.8em"> kmGLPopMatrix();
复制代码
效果图如下:
注:
CCPointArray解释
CCPointArray是一个包含控制点的数组,使用方法如上 原文链接:https://www.f2er.com/cocos2dx/339997.html