DrawNode簡單繪圖示例如下:
DrawNode* drawNode=DrawNode::create();
//繪制空心4邊形和直線
Vec2 point[4];
point[0] = Vec2(100, 100);
point[1] = Vec2(100, 200);
point[2] = Vec2(200, 200);
point[3] = Vec2(200, 100);
drawNode-> drawPolygon (point, 4 , Color4F :: BLUE , 5 , Color4F :: RED );
drawNode->drawLine(Point(100,220),Point(300,220),Color4F::GRAY);
this->addChild(drawNode);
drawNode.drawCardinalSpline(config, tension, segments, lineWidth, color)
//曲線 參數說明: //congfig:點數組 //tension:張力 //segments:段落 //lineWidth:線條寬度 //color:顔色
drawNode.drawCatmullRom(points, segments, lineWidth, color)
//同上
drawNode.drawCircle(center, radius, angle, segments, drawLineToCenter, lineWidth, color)
//畫圓 //參數說明: 原點,半徑,弧度,分段(越大越接近圓),原點到弧度的線(boolean),線條寬度,顔色
drawNode.drawCubicBezier(origin, control1, control2, destination, segments, lineWidth, color)
//畫三次貝塞爾曲線 //
drawNode.drawCubicBezier(cc.p(s.width - 250, 40), cc.p(s.width - 70, 100), cc.p(s.width - 30, 250), cc.p(s.width - 10, s.height - 50),10,1, cc.color(0, 1, 0, 1)); drawNode.drawQuadBezier(origin, control, destination, segments, lineWidth, color)
//畫二次貝塞爾曲線 參考三次貝塞爾曲線
drawNode.drawDot(pos, radius, color)
//畫點 //
drawNode.drawDot(cc.p(60, 100), 20, cc.color(0.5,0.6,0,1)); drawNode.drawDots(points, radius, color)
//畫點 points 點數組
drawNode.drawPoly(verts, fillColor, lineWidth, color)
//畫多邊形
drawNode.drawRect(origin, destination, fillColor, lineWidth, lineColor)
//畫矩形
drawNode.drawSegment(from, to, lineWidth, color)
//畫線段