在class HelloWorld : public cocos2d::CCLayer中添加
void draw();
实现:
void HelloWorld::draw() { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCPointArray *array = CCPointArray::create(20); array->addControlPoint(ccp(0, 0)); array->addControlPoint(ccp(80, 80)); array->addControlPoint(ccp(s.width - 80, 80)); array->addControlPoint(ccp(s.width - 80, s.height - 80)); array->addControlPoint(ccp(80, s.height - 80)); array->addControlPoint(ccp(80, 80)); array->addControlPoint(ccp(s.width / 2, s.height / 2)); CCPointArray *array2 = CCPointArray::create(20); array2->addControlPoint(ccp(s.width / 2, 30)); array2->addControlPoint(ccp(s.width -80, 30)); array2->addControlPoint(ccp(s.width - 80, s.height - 80)); array2->addControlPoint(ccp(s.width / 2, s.height - 80)); array2->addControlPoint(ccp(s.width / 2, 30)); //个人理解是初始化用来存放点的栈 kmGLPushMatrix(); //定义栈的大小 kmGLTranslatef(50, 50, 0); //绘制曲线 ccDrawCatmullRom(array, 50); //绘制完后弹出所存放的点 kmGLPopMatrix(); //由于上面只是弹出并不是释放,所以仍然可以通过点栈来绘制曲线 ccDrawCatmullRom(array2,50); }
然后直接运行就可以了
补充: