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

    然后直接运行就可以了

    补充:

  • 相关阅读:
    AI ResNet V1
    Lua基础
    git命令小结
    定时器及时间轮
    expect
    vscode 常用快捷键
    动态链接库与共享内存:
    container_of机制
    ELF文件格式
    git学习补充
  • 原文地址:https://www.cnblogs.com/newlist/p/3204212.html
Copyright © 2020-2023  润新知