本文章主要讲解cocos2d画图,代码分享给大家,有需要的朋友可以参考下。
这是cocos2d中的一些画图的例子代码
- (void) draw{
CGSize s = [[CCDirector sharedDirector] winSize];
// draw a simple line
// The default state is:
// Line Width: 1
// color: 255,255,255,255 (white, non-transparent)
// Aliased
ccDrawLine( ccp(0, 0), ccp(s.width, s.height) );
// line: color, width, anti-aliased
glLineWidth( 5.0f );
glEnable(GL_LINE_SMOOTH);
glColor4ub(255,0,0,255);
ccDrawLine( ccp(0, s.height), ccp(s.width, 0) );
// TIP:
// Since nobody disabled GL_LINE_SMOOTH,
// it will be valid until somone disabled it.
// The followin examples will be drawn using anti-aliasing.
//
// Remember: OpenGL is a state-machine.
// draw big point in the center
glPointSize(64);
glColor4ub(0,0,255,128);
ccDrawPoint( ccp(s.width / 2, s.height / 2) );
// draw 4 small points
CGPoint points[] = { ccp(60,60), ccp(70,70), ccp(60,70), ccp(70,60) };
glPointSize(4);
glColor4ub(0,255,255,255);
ccDrawPoints( points, 4);
// draw a green circle with 10 segments
glLineWidth(16);
glColor4ub(0, 255, 0, 255);
ccDrawCircle( ccp(s.width/2, s.height/2), 100, 0, 10, NO);
// draw a green circle with 50 segments with line to center
glLineWidth(2);
glColor4ub(0, 255, 255, 255);
ccDrawCircle( ccp(s.width/2, s.height/2), 50, CC_DEGREES_TO_RADIANS(90), 50, YES);
// open yellow poly
glColor4ub(255, 255, 0, 255);
glLineWidth(10);
CGPoint vertices[] = { ccp(0,0), ccp(50,50), ccp(100,50), ccp(100,100), ccp(50,100) };
ccDrawPoly( vertices, 5, NO);
// closed purble poly
glColor4ub(255, 0, 255, 255);
glLineWidth(2);
CGPoint vertices2[] = { ccp(30,130), ccp(30,230), ccp(50,200) };
ccDrawPoly( vertices2, 3, YES);
// restore original values
glLineWidth(1);
glDisable(GL_LINE_SMOOTH);
glColor4ub(255,255,255,255);
glPointSize(1);