为精灵划定轨迹路线 之 CCCardinalSplineTo

<1>我们做游戏的时候经常需要一个精灵移动,比如怪物 boss等等,但是只是单纯的加减x y坐标的话往往满足不了我们的需求,在此我为需要的朋友们介绍一下怎么给一个精灵添加轨迹路线 其实很简单 代码如下:

//创建精灵 Boss
Boss =CCSprite::create("diji.png");
Boss->setPosition(ccp(320, 1000));//Boss坐标
this->addChild(Boss);

//创建坐标组 并添加坐标
CCPointArray * bosspoints=CCPointArray::create(18);
bosspoints->addControlPoint(ccp(250, 980));
bosspoints->addControlPoint(ccp(350, 800));
bosspoints->addControlPoint(ccp(450, 650));
bosspoints->addControlPoint(ccp(500, 500));
bosspoints->addControlPoint(ccp(450, 350));
bosspoints->addControlPoint(ccp(350, 200));
bosspoints->addControlPoint(ccp(250, 350));
bosspoints->addControlPoint(ccp(150, 500));
bosspoints->addControlPoint(ccp(50, 650));
bosspoints->addControlPoint(ccp(150, 800));
bosspoints->addControlPoint(ccp(250, 980));
bosspoints->addControlPoint(ccp(150, 980));
bosspoints->addControlPoint(ccp(50, 980));
bosspoints->addControlPoint(ccp(150, 980));
bosspoints->addControlPoint(ccp(250, 980));
bosspoints->addControlPoint(ccp(350, 980));
bosspoints->addControlPoint(ccp(450, 980));
bosspoints->addControlPoint(ccp(350, 980));
bosspoints->addControlPoint(ccp(250, 980));

//根据坐标组创建一个轨迹 三个参数是 移动一轮的时间,坐标组,浮张力(惯性)
CCActionInterval * bosslineTo=CCCardinalSplineTo::create(18, bosspoints, 0);

//让boss执行这个行动 CCRepeatForever是一直执行
Boss->runAction(CCRepeatForever::create(bosslineTo));


你可能感兴趣的:(为精灵划定轨迹路线 之 CCCardinalSplineTo)