今天,我们来学习cocos2d3.x绘制图形DrawNode:

bool HelloWorld::init()

{

//////////////////////////////

// 1. super init first

if ( !Layer::init() )

{

return false;

}

//绘制三角形,点和多边形

Point points[] = { Point(400, 400), Point(400, 500), Point(500, 500), Point(500, 400)};

auto dn = DrawNode::create();

dn->drawTriangle(Point(100,100),Point(200,200),Point(100,300),Color4F::WHITE);

dn->drawDot(Point(700,300),100,Color4F::GREEN);

dn->drawPolygon(points,sizeof(points)/sizeof(points[0]),Color4F::BLUE,2,Color4F::WHITE);

addChild(dn);

return true;

}

效果: