首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

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

2013-01-27 
cocos2d-x画实心圆(不更改cocos2d的类库)画实心圆,不改COCOS2d-x类库,兼容性好。封装了一下,就这样:放在Dra

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

热点排行