读书人

cocos2d-x画实心圆(不更动cocos2d的类

发布时间: 2013-01-27 13:56:15 作者: rapoo

cocos2d-x画实心圆(不更改cocos2d的类库)

画实心圆,不改COCOS2d-x类库,兼容性好。

封装了一下,就这样:

放在DrawUtils.h里面

#pragma once#include "cocos2d.h"using namespace cocos2d;class DrawUtils{public:static void drawSolidCircle(const CCPoint& center,float radius,unsigned int segments,ccColor4F color){const float coef = 2.0f * (float)M_PI/segments;CCPoint *vertices=(CCPoint*)calloc(segments+1,sizeof(CCPoint));for(unsigned int i = 0;i <= segments; i++) {float rads = i*coef;GLfloat j = radius * cosf(rads)  + center.x;GLfloat k = radius * sinf(rads)  + center.y;vertices[i].x=j;vertices[i].y=k;}ccDrawSolidPoly( vertices, segments,color);free(vertices);}};

使用方法:

DrawUtils::drawSolidCircle(ccp(0,0),m_attackRange,30,ccc4f(0,255,0,0.5));

so easy

读书人网 >操作系统

热点推荐