cocos2d-x画线

在class HelloWorld : public cocos2d::CCLayer中添加

void draw();

实现:

void HelloWorld::draw()
{ CCSize s = CCDirector::sharedDirector()->getWinSize();
CCPointArray *array = CCPointArray::create(); array->addControlPoint(ccp(, ));
array->addControlPoint(ccp(, ));
array->addControlPoint(ccp(s.width - , ));
array->addControlPoint(ccp(s.width - , s.height - ));
array->addControlPoint(ccp(, s.height - ));
array->addControlPoint(ccp(, ));
array->addControlPoint(ccp(s.width / , s.height / )); CCPointArray *array2 = CCPointArray::create(); array2->addControlPoint(ccp(s.width / , ));
array2->addControlPoint(ccp(s.width -, ));
array2->addControlPoint(ccp(s.width - , s.height - ));
array2->addControlPoint(ccp(s.width / , s.height - ));
array2->addControlPoint(ccp(s.width / , ));
//个人理解是初始化用来存放点的栈
kmGLPushMatrix();
//定义栈的大小
kmGLTranslatef(, , );
//绘制曲线
ccDrawCatmullRom(array, );
//绘制完后弹出所存放的点
kmGLPopMatrix();
//由于上面只是弹出并不是释放,所以仍然可以通过点栈来绘制曲线
ccDrawCatmullRom(array2,);
}

然后直接运行就可以了

补充:

上一篇:MVC实现更新数据库的数据


下一篇:javascript正则表达式学习(二)--位置匹配