cocos2d-x绘制直线
封装一个CCNode,重写draw函数,使用opengl函数绘制直线,done!
Line *Line::create(float h,float w,const ccColor4B &colorValue) { Line * result = new Line(); if (result) { result->initLine(h,w, colorValue); result->autorelease(); return result; } CC_SAFE_DELETE(result); return NULL; } void Line::draw() { CCNode::draw(); CHECK_GL_ERROR_DEBUG(); glLineWidth(h); ccDrawColor4B(color.r, color.g, color.b, color.a); ccDrawLine( ccp(0,0), ccp(w,0)); glLineWidth(1); ccDrawColor4B(255,255,255,255); ccPointSize(1); CHECK_GL_ERROR_DEBUG(); } void Line::initLine(float h0 ,float w0,const ccColor4B &colorValue) { w = w0; h = h0; color = colorValue; }