create ccDrawLine problem

create ccDrawLine problem
0.0 0


I want to use ccDrawLine to create the line.
glColor4f() function can change the line color, But the glColor4f is undefined.
how can i solve this problem?


Hi wing lau,

To change drawing color, use ccDrawColor4F and after call ccDrawLine.

cocos2d::CCSize screenSize = cocos2d::CCDirector::sharedDirector()->getWinSize();

//red line from bottom left to top right corner
cocos2d::ccDrawColor4F(1.0f, 0.0f, 0.0f, 1.0f);
cocos2d::ccDrawLine(ccp(0,0), ccp(screenSize.width, screenSize.height));

//green line from bottom right to top left corner
cocos2d::ccDrawColor4F(0.0f, 1.0f, 0.0f, 1.0f);
cocos2d::ccDrawLine(ccp(screenSize.width,0), ccp(0, screenSize.height));



Thanks you.
But i have used the code

cocos2d::ccDrawColor4F(1.0f, 0.0f, 0.0f, 1.f);
cocos2d::ccDrawLine( CCPointMake(0, 0), CCPointMake(20,20) );

and then i can’t see the line.:frowning:


I take a screenshot from my Tab with my sample :

As you can see, on my device ( 1024 x 600, forced to 480 x 320 ) lines don’t start from corner.
Maybe you have similar transformation, can you try to draw lines longer ?

I test your code and I see red line behind FPS information.


i have found the problem, the ccDrawline function need use the draw() method.
I want to click the sprite, and then draw the line.
But the draw() method will draw the line when i start the program.
It has other way to create the line?


In your YourScene::ccTouchesBegan function, set a flag to true and in your YourScene::draw test this flag and draw your line.
If the ccDrawline call is not in draw function, the line will be erase by the screen refresh at each frame, I guess.


Yeap, you should draw line every frame, or it will be erased.


Has anybody tried to draw lines in OpenGL ES 2.0 ? I need to know if there is some way to draw the line without seeing pixels.

Thank you in advance.