如何在cocos2dx中绘制圆圈

时间:2014-09-20 08:50:24

标签: android cocos2d-x cocos2d-x-3.0

如何在cocos2dx 3.0中绘制圆或线。

我的代码是

DrawNode *drawnode = DrawNode::create();
drawnode->drawDot(ccp(15,Director::sharedDirector()->getVisibleSize().height/2),50,Color4F(255,255,255,255));

this->addChild(drawnode);

1 个答案:

答案 0 :(得分:5)

画一条线cocos2d-x有功能 drawsegment

圆是特殊类型的多边形 所以对于圆形使用drawpolygon函数

// for line

 draw->drawSegment(startPoint, moved, 5,Color4F(1,222,120,1) );

// for circle

static CCPoint Circle [nCount]; // vertex array
for ( int i = 0 ; i <nCount; i ++) {
    float rads = i * coef; // radians
    Circle [i] .x = Radius * cosf (rads); //vertex x
    Circle [i] .y = Radius * sinf (rads); //vertex y
}
draw-> drawPolygon (Circle, nCount, blue, 0 , red);