cocos2d-x画线

在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);
}

 

然后直接运行就可以了

补充:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值