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

前端之家收集整理的这篇文章主要介绍了cocos2d-x-3.2 (一)两种方法画基本图形前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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(),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,255);

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

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

}

猜你在找的Cocos2d-x相关文章