现在的位置: 首页 > 综合 > 正文

cocos2d-x-3.2 (一)两种方法画基本图形

2017年09月16日 ⁄ 综合 ⁄ 共 953字 ⁄ 字号 评论关闭

1:

    auto s =
Director::getInstance()->getWinSize();

   
auto draw = DrawNode::create();

   
this->addChild(draw);

   
for (int i =
0; i < 10; i++) {

        draw->drawDot(Vec2(s.width*0.5,s.height*0.5),
10*(10-i), 
Color4F(CCRANDOM_0_1(),
CCRANDOM_0_1(), CCRANDOM_0_1(),
1));

    }

2:

void
HelloWorld::draw(Renderer *renderer,
const Mat4 &transform,
uint32_t flags)

{

    _customCommand.init(1);

   
_customCommand.func =
CC_CALLBACK_0(HelloWorld::onDraw,this,transform,flags);

    renderer->addCommand(&_customCommand);

}

void
HelloWorld::onDraw(const
Mat4 &transform, uint32_t flags)

{

    Director::getInstance()->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);

   
Director::getInstance()->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform);

   
//直线

    CHECK_GL_ERROR_DEBUG();

    glLineWidth(5.0f);

    DrawPrimitives::setDrawColor4B(255,0,0,255);

    DrawPrimitives::drawLine(VisibleRect::leftBottom(),
VisibleRect::rightTop());

    

    Director::getInstance()->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);

}

抱歉!评论已关闭.